DEV Community

Shriharsh
Shriharsh

Posted on • Edited on

4

Today I Learned: About Docker Volume

Docker Volume

In my experiements on running Jenkins on Docker, I wondered how the volumne worked when I provided -v to the run command.

I found a great article which succintly explains a lot about the Docker Volume - which will be handy for any docker beginer.

Original article is here

My summary goes below:

  • Docker Volume is the way to persist data between container restarts and share it between containers.
  • A volume is stored on the host file system. Usually within obscure directories inside /var/lib/docker. However, a specific directory on host system can also be mounted as volume in a container.
  • Volumes can be managed using docker volume and its sub commands.
  • Docker won't delete volume unless specifically instructed to do so. This can result in stale data on the host system. So tidying up once in a while might come handy.
  • Important Caveat - Don't try to modify the content of the volume in the Dockerfile (via RUN) as each build step creates a new volume and your changes will be discarded. If you want to change the volume content, do so using the ENTRYPOINT command in the Dockerfile. Have a look at this link.
  • If you are looking for a thorough overview of different approaches to manage application data, including the use of Volume, Bind mounts, tmpfs mounts, read this longer article

Image Credit: https://docs.docker.com/engine/admin/volumes/images/types-of-mounts-volume.png

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs