Volumes From Another ContainerΒΆ

Volumes from a container can be bound to another container using --volumes-from <container-name flag. Make sure there is host directory with contents /ubuntu1/code

$ ls /ubuntu1

Create a Container with a Volume Create a container with name ubuntu1 from image ubuntu

$ docker run -it --name ubuntu1 -v /ubuntu1:/ubuntu1 ubuntu
root@f031b82e5da6:/# ls ubuntu1

Create Second Container with shared volumes

Create a second container ubuntu2 with volumes from ubuntu1

$ docker run -it --name ubuntu2 --volumes-from ubuntu1 ubuntu

Note : -volumes-from is also valid but deprecated.

Check that the ubuntu1 volume is bound as expected

root@b28ca7033e9d:/# ls
bin  boot  dev  etc  home  ..  ubuntu1  usr  var
root@b28ca7033e9d:/# ls ubuntu1