What is the exact difference between the two flags used in docker volume commands -v
and --volumes-from
. It seems to me that they are doing the same work, consider the following scenario.
First lets create a volume named myvol
using command:
$ docker volume create myvol
Now create and run a container named c1
that uses myvol
and get into his bash:
$ docker run -it --name c1 -v myvol:/data nginx bash
Lets create a file test.txt
in the mounted directory of the container as:
root@766f90ebcf37:/# touch /data/test.txt
root@766f90ebcf37:/# ls /data
test.txt
Using -volume
flag:
Now create another container named c2
that also uses myvol
:
$ docker run -it --name c2 -v myvol:/data nginx bash
As expected, the new generated container c2
also have access to all the files of myvol
root@393418742e2c:/# ls /data
test.txt
Now doing the same thing with --volumes-from
Creating a container named c3
using volumes from container c1
$ docker run -it --name c3 --volumes-from c1 nginx bash
This will result the same thing in c3
:
root@27eacbe25f92:/# ls /data
test.txt
The point is if -v
and --volumes-from
are working the same way i.e. to share data between containers then why they are different flags and what --volumes-from
can do that -v
cannot do?