Thursday, July 8, 2021

Docker Volumes - File Locations for docker which Persist after container

https://www.freecodecamp.org/news/where-are-docker-images-stored-docker-container-paths-explained/

https://stackoverflow.com/questions/34809646/what-is-the-purpose-of-volume-in-dockerfile/34810191#34810191


https://www.docker.com/blog/how-to-use-the-official-nginx-docker-image/   [Example]

Docker Volumes

It is possible to add a persistent store to containers to keep data longer than the container exists or to share the volume with the host or with other containers. A container can be started with a volume by using the -v option:

$ docker run --name nginx_container -v /var/log nginx
We can get information about the connected volume location by:
$ docker inspect nginx_container 

Adding Custom HTML

By default, Nginx looks in the /usr/share/nginx/html directory inside of the container for files to serve. We need to get our html files into this directory. A fairly simple way to do this is use a mounted volume. With mounted volumes, we are able to link a directory on our local machine and map that directory into our running container.

docker run -it --rm -d -p 8080:80 --name web -v ~/site-content:/usr/share/nginx/html nginx

docker    run   -v    /path/to/host/directory:/path/inside/the/container    image

When a docker container is deleted,
volume is not deleted by itself, atleast not by default.

Clean up space used by Docker

It is recommended to use the Docker command to clean up unused containers. Container, networks, images, and the build cache can be cleaned up by executing:

$ docker system prune -a

Additionally, you can also remove unused volumes by executing:

$ docker volumes prune

No comments:

Post a Comment

Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass