Skip to content

hirampv/docker_apache_resume

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

docker_apache_resume

A Docker container with Apache web server hosting a static html with my resume

Dockerfile Documentation

Overview

This Dockerfile creates a containerized environment based on the latest Ubuntu image. It installs and configures Apache HTTP Server to serve a provided index.html file.

Dockerfile Breakdown

Base Image

FROM ubuntu:latest
  • Uses the latest Ubuntu image as the base.
  • Ensures a reliable and well-supported environment.

Installing Dependencies

RUN apt-get update && apt-get install -y tzdata
RUN apt-get install apache2 --yes
  • Updates the package list to get the latest available versions.
  • Installs tzdata to configure time zone settings.
  • Installs Apache2 (apache2 package) to serve web pages.

Copying HTML File

COPY index.html /var/www/html/index.html
  • Copies a local index.html file into the Apache document root at /var/www/html/index.html.
  • This ensures that the default Apache web page is replaced with the provided index.html.

Setting the Default Command

CMD ["apachectl", "-D", "FOREGROUND"]
  • Runs the Apache server in the foreground to keep the container running.
  • Uses apachectl (Apache control interface) with the FOREGROUND option so that the server doesn't daemonize and allows Docker to manage it properly.

Building and Running the Container

Build the Image

docker build -t my-apache-server .
  • This command builds the Docker image and tags it as my-apache-server.
  • Ensure that the index.html file is in the same directory as the Dockerfile before running this command.

Run the Container

docker run -d -p 8080:80 --name apache-container my-apache-server
  • Runs the container in detached mode (-d).
  • Maps port 8080 on the host to port 80 inside the container (-p 8080:80).
  • Names the container apache-container.

Verify the Web Server

After running the container, you can access the Apache server by opening the following URL in a browser:

http://localhost:8080

If the setup is correct, it should display the contents of the index.html file.

Stopping and Removing the Container

To stop the running container:

docker stop apache-container

To remove the container:

docker rm apache-container

To remove the Docker image:

docker rmi my-apache-server

Potential Improvements

  • Use a smaller base image like ubuntu:20.04 to ensure stability.
  • Merge installation steps into a single RUN command to optimize layer caching:
    RUN apt-get update && apt-get install -y tzdata apache2 && rm -rf /var/lib/apt/lists/*
  • Add a HEALTHCHECK directive to monitor Apache’s health.
    HEALTHCHECK --interval=30s --timeout=10s \
        CMD curl -f http://localhost || exit 1
  • Use a non-root user for better security.

Conclusion

This Dockerfile provides a simple and effective way to containerize an Apache web server using Ubuntu. By following best practices, it can be improved for efficiency, security, and maintainability.

About

A Docker container with Apache web server hosting a static html with my resume

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published