Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Docker Volumes

Docker Volumes:

Docker gives feature called volume, to share the data between networks.

there are two varieties

  • Persistent – Store the data perminently even container stopped, the data will be exists.
  • Ephemeral – Temp data, if container stopped, the data will be no longer available.

Share Folder with the host:

  • “Shared folders” with the host.
  • Sharing a file into a container.
  • Data will be available even container stopped.

Example for Persistent:

Step 1: open “Docker Quickstart Terminal”

Step 2: running on linux host

docker-machine ssh

Step 3: create a new folder named as “drtuts”

mkdir drtuts

Step 4: find out the complete path of the folder.

pwd

Step 5:

docker run --rm -ti -v /home/docker/drtuts:/shared-folder ubuntu bash

Step 6: go to Shared-folder

cd shared-folder

Step 7: creating new data which is going to share to docker machine.

touch my-data-file

Step 8: exit container

exit

Step 9: go to “drtuts”

cd /home/docker/drtuts

Step 10: list out all the files

ls

Note: if you exist the container & linux host, the file still be available in the host.

Sharing data between containers:

volumes-from attributes helps to share data between containers.

Shared “Discs” that exists only as long as they are being used.

Its common for the containers which being used

Examples:

Step 1: open “Docker Quickstart Terminal”

Step 1: Start container with created new shared folder between containers.

docker run --rm -ti -v /share-data ubuntu bash

Step 2: Create a new file named as Vijay within share-data folder.

echo Vijay > /share-data/vijay-file

Step 3: Start another container using another “Docker Quickstart Terminal” which refers share-data folder.

docker run --rm -ti --volumes-from /share-data ubuntu bash

Step 4: go to Share-data folder

cd share-data

Step 5: List out all the files

ls

Now the share-data folder is shared between containers, where you can share the data between containers using this directory. But its available as long as those containers being used.

The post Docker Volumes appeared first on Drtuts.



This post first appeared on Drtuts, please read the originial post: here

Share the post

Docker Volumes

×

Subscribe to Drtuts

Get updates delivered right to your inbox!

Thank you for your subscription

×