3

Docker: Reciprocating volumes

I am creating two containers running 2 different applications. Container A, exposes 2 directories say /opt/appA and /home/userA/runtime. Both are needed to be referred to by container B (--volumes-from A). B in turn should expose a volume /home/userB/runtime, which container A needs (--volumes-from B) when it starts.

Q. is how to achieve this? Because when I start/run container 'A', container 'B' does not yet exist (--volumes-from B does not work) and vice versa for B.

Is there a way out of this?

yogmk
  • 161
  • 10

1 Answers1

2

Simply create separate volumes (and use them in A and B) with the docker 1.9 docker volume create command.

That way, A and B can mount those volumes when they are launched.
One volume can be mounted (-v) by multiple containers.

$ docker volume create --name optA
optA

$ docker run --name=A -d -v optA:/opt/appA busybox ls /opt/appA
$ docker run --name=B -d -v optA:/opt/appA busybox ls /opt/appA

No more --volume-from needed.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I had built images with `docker commit` and they already had data in the directories in /opt/AppA etc. So when I create a separate volume and mount the directories, the already present data in the image is shadowed by empty directories from the volume. But that's more of a workflow problem. I should have mounted the volume first and then installed the application/s in /opt/appA etc. Using `docker volume create` is a good solution though. Thanx. – yogmk Mar 04 '16 at 17:24
  • That is the idea indeed: the new volume API helps making volumes more visible. – VonC Mar 04 '16 at 17:27