Docker Volumes
A docker volume allows you to persist data generated by and used by Docker containers. A volume can exist on the host, be available in the container and doesn’t increase the size of the container using it. The container exists outside the life cycle of a given container, meaning that even if you kill the container, the volume will stay in tact. Another benefit is that a volume can be shared amongst multiple containers. Volumes can be managed by the Docker CLI which makes it extremely easy and volumes can also be hosted on cloud storage which opens the doors to a wide range of functionality and options.
You can create a volume in numerous ways.
With a docker compose you can specify:
The cool thing with a docker compose is that you can use environment variables for dynamic replacement of values so if you use a CI/CD, like Jenkins you can have the location be dynamic:
Using the docker API we can create and manage volumes:
Using the docker run command we can attach a volume to a container as well. If the volume doesn’t exist yet, Docker will create it for you
Check the documentation for docker-compose volumes. Curious how to do the same in Kubernetes? Check out our post on shared volumes in kubernetes - using hostPath.
Read more about it here