Serving my first web page with Apache in a local Docker container

I am setting up Docker for my local development environment.

My first step in just understanding how to server a simple HTML page from an Apache 2 webserver.

After installing Docker, I ran this command:

docker run --name my-apache-app -p 80:80 httpd:2.4

The command docker run creates a Docker container from a Docker image and starts the container.

This grabs the official Docker Apache 2 image and names my container "my-apache-app". I tell the container to use port 80. 

After the container is running I can then view my HTML page by visiting localhost:80 in my browser

This will get you the default page served by Apache.

The idea here is that you don't want to simply serve the default Apache 2 page. 


This is not a very efficient way of doing this but you could change the the HTML file that Apache serves from the command line in the container

The default Docker Apache image uses the Debian Linux distribution. 

It server httpd docs from the /usr/local/apache3/htdocs directory

If you navigate to this directory you can edit the default index.html file

cd /usr/local/apache2/htdocs

You will likely find that there is no editor install in your container. You can quickly solve this

apt-get update
apt-get install nano

And now you can edit index.html and when you visit localhost:8080 you will see your new webpage.


Remember, if you can stop and start this container without losing any edits

 docker stop my-apache-app
 docker start my-apache-app

But if you destroy the container and rebuild it from it's image it will revert to the image's initial state.