How to share volumes or contents between containers ?

In this article I am going to show you how to share the contents between containers. Contents can be shared between containers using the volumes Below are my setup details. –> Redhat Atomic Host –> Creating two container using same volume.

Step 1 : I have created new container with name vicky3.

Atomic# docker run -i -v /var/volume1 -name vicky3 -t rhel /bin/bash

After issuing the above new prompt will come. In /var of container you can see the volume (volume1) shown as directory.

bash-4.2# cd var/ adm/      db/       games/    kerberos/ local/    log/      nis/      preserve/ spool/    volume1/ cache/    empty/    gopher/   lib/      lock      mail/     opt/      run/      tmp/      yp/

Step 2 : I went into volume1 directory and create new files inside it.

bash-4.2# touch file1

bash-4.2# touch file2

Step 3 : Time to create new container using the same volume. This time I have not given any name to container.

Atomic# docker run -i –volumes-from vicky3 -t rhel /bin/bash

I went to same volume volume1 and list the contents. I can see that two files are present which we have created in vicky3 container.

bash-4.2# cd /var/volume1/

bash-4.2# ls file1  file2

Step 4 : I created new file in it from the new container.

bash-4.2# touch file3

I am able to see the new file in vicky3 container as well.

Step 5 : If you want to check the volume contents on atomic host, you need to go to below path.

Atomic# ls /var/lib/docker/vfs/dir/85b51dad82f897941aaadc9c6131545d3292681184f796404350eeeb4abc32ed/*
file1  file2  file3

#### Now question arises Whats the use of volume in container.

  1. You want to be able to share a directory between containers
  2. You intend on writing large amounts of data to a directory, for example, for a database.

You may refer the below link for more information.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s