MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Docker Tutorials: Volume – Deep Dive

In order to understand what a Docker volume is, we first need to be clear about how the filesystem normally works in Docker. Docker images are stored as series of read-only layers. When we start a container, Docker takes the read-only image and adds a read-write layer on top. If the running container modifies an existing file, the file is copied out of the underlying read-only layer and into the top-most read-write layer where the changes are applied. The version in the read-write layer hides the underlying file, but does not destroy it — it still exists in the underlying layer.

When a Docker container is deleted, relaunching the image will start a fresh container without any of the changes made in the previously running container — those changes are lost. Docker calls this combination of read-only layers with a read-write layer on top a Union File System.

Diagram of a thin read-write container layer on top of four read-only image layers on Ubuntu 15.04

Docker has two options for containers to store files in the host machine, so that the files are persisted even after the container stops: volumes, and bind mounts. If you’re running Docker on Linux you can also use a tmpfs mount.

An easy way to visualize the difference among volumes, bind mounts, and tmpfs mounts is to think about where the data lives on the Docker host.

Diagram of Docker mount types: bind mount and volume to the host filesystem, tmpfs mount to memory

  1. Volumes – Volumes are stored in a part of the host filesystem which is managed by Docker (/var/lib/docker/volumes/ on Linux). Volumes are the best way to persist data in Docker.
  2. Bind mounts – Bind mounts may be stored anywhere on the host system. They may even be important system files or directories. Non-Docker processes on the Docker host or a Docker container can modify them at any time.
  3. tmpfs – tmpfs mounts are stored in the host system’s memory only, and are never written to the host system’s filesystem.

What are docker volumes?
Docker volumes are the preferred mechanism for persisting data generated by and used by Docker Containers. These are use of Volume…

  1. Decoupling container from storage
  2. Share volume (storage/data) among different containers
  3. Attach Volume to a container
  4. On Deleting container volume does not delete

Commands Collection

# How to create docker volume?
$ docker volume create myvol1

# How to list the docker volume?
$ docker volume ls

# How to inspect docker volume?
$ docker volume inspect vol-name

# How to delete docker volume?
$ docker volume rm vol-name

# How to attach Volume to a containers? or
# How to share volume among containers?
$ docker run --name jenkins1 -v myvol1:/var/jenkins_home -p 8080:8080 -p 50000:50000 jenkins
$ docker run --name jenkins2 -v myvol1:/var/jenkins_home -p 8085:8080 -p 50005:50000 jenkins[

# How to use Bind mounts storage in Docker Volume?
$ docker run --name jenkins2 -v /opt/jenkins:/var/jenkins_home -p 8090:8080 -p 50010:50000 jenkins
$ docker run --name jenkins2 -v /opt/jenkins:/var/jenkins_home -p 8095:8080 -p 50015:50000 jenkins

# Difference between the -v or --mount flag in Docker?
Originally, the -v or --volume flag was used for standalone containers and the --mount flag was used for swarm services. However, starting with Docker 17.06, you can also use --mount with standalone containers. In general, --mount is more explicit and verbose.

# The biggest difference is that the -v syntax combines all the options together in one field, while the --mount syntax separates them.
$ docker run -d --name devtest --mount source=myvol2,target=/app nginx:latest
$ docker run -d --name devtest -v myvol2:/app nginx:latest

# This commands will not work as its --mount require only volume type. but not the mounts.
docker run -d --name devtest --mount source=/opt/backup1,target=/var/jenkins_home jenkins
Code language: PHP (php)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Freeing GB on Your Mac: Cleaning Docker, Brew, and Dev Tools

As a developer, there’s that one afternoon, mid-sprint, when a build fails. Not because of bad code, but because your Mac has run out of disk space….

Read More

Docker Tutorials: Remove all Docker Containers, all Images, all Volumes, and all Networks

How to stop all Docker Containers To delete all containers including its volumes use How to remove all stopped Docker Containers How to delete all Docker Images…

Read More

Docker Tutorials: Docker Image – Example and Sample Programs of Dockerfile

This page collects sample Dockerfiles that build an Ubuntu-based Apache image and show how CMD, ENTRYPOINT, EXPOSE, ARG, ENV, COPY and USER behave. Below the examples you…

Read More

Kubernetes: Pull an Image from a Private Registry using Yaml and Helm File

Kubernetes pulls images from a private registry using a kubernetes.io/dockerconfigjson Secret. A Pod references that Secret through imagePullSecrets, either directly or through its ServiceAccount. This page shows…

Read More

Docker Training Agenda: A Hands-On Learning Path from Containers to Registries and Networking

This revised Docker training agenda turns the original outline into a practical, modern learning path for beginners and early-career DevOps engineers. It maps each module to hands-on outcomes, core commands, and common implementation decisions.

Read More

Install Jenkins with Docker: Persistent Setup, Port Mapping, and Logs

Learn how to run Jenkins in Docker with correct port mapping, persistent storage, and operational commands. This updated guide keeps the original workflow but adds modern, production-minded practices.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x