Docker Volumes
Table of contents
What is a Docker volume
In short, it maps the volume inside a container with some local directory on your computer.
If you set the volume to read-only, every change in local directory will be reflected in the container but not vice versa.
If you set read-only to false, the contents inside the container and the local directory will remain same throughout the container execution.
Cases where Docker volume comes in handy
You want some live-reloading features
During development, it is really painful if you have to rebuild or rerun everytime you make a change.
By mapping your container volume to a local build context, the container will update itself everytime you make a change to your local code.
You want to persist data upon container shutdown
For example if you’re running a DB as a container without a volume mapped, each time the container restarts, the contents of the DB will be erased.
However, if you map your container volume to a local directory, the data will be kept even after shutdown.