14

Why does docker have docker volumes and volume containers? What is the primary difference between them. I have read through the docker docs but couldn't really understand it well.

Manohar Negi
  • 445
  • 5
  • 12

1 Answers1

23

Docker volumes

You can use Docker volumes to create a new volume in your container and to mount it to a folder of your host. E.g. you could mount the folder /var/log of your Linux host to your container like this:

docker run -d -v /var/log:/opt/my/app/log:rw some/image

This would create a folder called /opt/my/app/log inside your container. And this folder will be /var/log on your Linux host. You could use this to persist data or share data between your containers.

Docker volume containers

Now, if you mount a host directory to your containers, you somehow break the nice isolation Docker provides. You will "pollute" your host with data from the containers. To prevent this, you could create a dedicated container to store your data. Docker calls this container a "Data Volume Container".

This container will have a volume which you want to share between containers, e.g.:

docker run -d -v /some/data/to/share --name MyDataContainer some/image

This container will run some application (e.g. a database) and has a folder called /some/data/to/share. You can share this folder with another container now:

docker run -d --volumes-from MyDataContainer some/image

This container will also see the same volume as in the previous command. You can share the volume between many containers as you could share a mounted folder of your host. But it will not pollute your host with data - everything is still encapsulated in isolated containers.

My resources

https://docs.docker.com/userguide/dockervolumes/

Thomas Uhrig
  • 30,811
  • 12
  • 60
  • 80
  • Thanks Thomas, that sounds good. Are they using the network protocol to communicate between the data volume container and the other container? Are they using TCP, UDP, Unix sockets or some other kind os communication protocol? Would this allow attaching a data volume container over the network? – Manohar Negi Jun 21 '14 at 07:44
  • 1
    Is there an easy docker command to show the existing volume containers? and possibly the data dependency structure? – B.Mr.W. Nov 01 '14 at 02:43
  • Volume containers are much the same as other Docker containers. The best way to tell which containers are being used as volume containers is to name them appropriately. Then you can tell quickly which are volume containers using the `docker ps` command. – freethebees Mar 04 '15 at 07:53
  • When I ctrl+f your source, the term "data volume container" doesn't exist. Did the source change ? – aaaaaa Feb 18 '23 at 13:34