A Docker container with Apache web server hosting a static html with my resume
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.
FROM ubuntu:latest- Uses the latest Ubuntu image as the base.
- Ensures a reliable and well-supported environment.
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
tzdatato configure time zone settings. - Installs Apache2 (
apache2package) to serve web pages.
COPY index.html /var/www/html/index.html- Copies a local
index.htmlfile 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.
CMD ["apachectl", "-D", "FOREGROUND"]- Runs the Apache server in the foreground to keep the container running.
- Uses
apachectl(Apache control interface) with theFOREGROUNDoption so that the server doesn't daemonize and allows Docker to manage it properly.
docker build -t my-apache-server .- This command builds the Docker image and tags it as
my-apache-server. - Ensure that the
index.htmlfile is in the same directory as the Dockerfile before running this command.
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.
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.
To stop the running container:
docker stop apache-containerTo remove the container:
docker rm apache-containerTo remove the Docker image:
docker rmi my-apache-server- Use a smaller base image like
ubuntu:20.04to ensure stability. - Merge installation steps into a single
RUNcommand to optimize layer caching:RUN apt-get update && apt-get install -y tzdata apache2 && rm -rf /var/lib/apt/lists/* - Add a
HEALTHCHECKdirective 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.
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.