Posted under » System Admin on 26 May 2025
From docker compose intro... . Lets now create a web page using docker compose where you can change and see the contents being changed without having to rebuild the image by using volume. We have covered docker volume previously here.
For this simpler scenario where you just want to show a html page served by a web server, you do not need a separate Dockerfile and compose.yaml like in the previous tutorial. You can combine them into a single docker-compose.yml.
version: '3.7' services: web: image: nginx:alpine ports: - "8001:80" volumes: - ./app:/usr/share/nginx/html
For ports, I put 8001 because 8000 was used by Flask in the previous tutorial.
The volumes directive will create a shared volume between the host machine and the container. This will share the local app folder with the container, and the volume will be located at /usr/share/nginx/html inside the container, which will then overwrite the default document root(/usr/share/nginx/html) for Nginx. The shared volume you’ve set up within the docker-compose.yml file keeps your app folder files in sync with the container’s document root. If you make any changes to the index.html file, they will be automatically picked up by the container and thus reflected on your browser when you reload the page.
Now that we have got that out the way, the following are some useful compose commands.
$ docker compose logs $ docker compose pause $ docker compose unpause $ docker compose stop $ docker compose down
What the last command (down) does is to remove the containers, networks, and volumes associated with this containerized environment.
$ docker image rm nginx:alpine
We have covered about container and volume housekeeping but you can remove images as well if you wish to save space.