Cloud Native 3 min read

Master Docker Data Volumes: Sharing Data Between Containers and Hosts

This guide explains how Docker data volumes enable file‑system sharing between containers and the host, covering volume concepts, mounting host directories, and using --volumes‑from to share data across multiple containers, with practical command examples and visual illustrations.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Master Docker Data Volumes: Sharing Data Between Containers and Hosts

Data Volume Concept

A data volume is a channel between a container and the external file system, allowing connection to the host’s file system or to other containers at the file level. Containers write data to their own volume, which other containers can mount and manipulate.

Typically a volume is a directory that can be mounted from the host or shared with other containers, solving data sharing between containers and the host or between containers.

Two Forms of Data Sharing

1. Mount a host directory as a volume

Mount an existing local directory into a container as a volume:

sudo docker run -d -P --name web -v /src/webapp:/opt/webapp training/webapp

The -v option creates a volume; /src/webapp:/opt/webapp maps the host directory before the colon to the container directory after the colon.

2. Share volumes between containers

Container A creates a volume: sudo docker run -it -v /dbdata --name dbdata ubuntu Container B mounts the volume from container A using --volumes-from: sudo docker run -it --volumes-from dbdata --name db1 ubuntu Any write to the shared directory by one container is visible to the others. Multiple containers can be attached using repeated --volumes-from parameters.

Example of mounting a volume from one container into another:

sudo docker run -d --name db2 --volumes-from db1 ubuntu
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerDevOpsContainerData Volume
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.