Start a simple web server with mounted document root


Clone the git repository if you haven’t done it yet.

Go to Project 1 from the git repository root:

cd projects/p01

Project structure:

└── www
    └── index.html

This project contains only one folder, “www” and an index.html in it with the following line:

Hello Docker (p01)

Start the container and mount “www” as document root:

docker run -d -v $(pwd)/www:/usr/local/apache2/htdocs:ro --name p01_httpd -p "8080:80" httpd:2.4
# or
docker run -d --mount type=bind,source=$(pwd)/www,target=/usr/local/apache2/htdocs,readonly --name p01_httpd -p "8080:80" httpd:2.4

Generate a domain name:
# example output:

In case are working in the cloned repository of this tutorial, you can also run the below command to set the variable


Test the web page:

Now you should see the content of the mounted index.html

Delete the container to make port 8080 free again.

docker rm -f p01_httpd