不,这在您的Dockerfile
.
--volumes-from
当您使用docker run
.
例子:
Dockerfile
FROM ubuntu:14.04
VOLUME /hello
然后:
$ docker build -t test-image-with-volume .
$ docker run -ti --name test-image-with-volume test-image-with-volume bash
/# cd /hello
/# ls -la
total 8
drwxr-xr-x 2 root root 4096 Jan 18 14:59 ./
drwxr-xr-x 22 root root 4096 Jan 18 14:59 ../
然后在另一个终端(虽然上面的容器仍在运行):
Dockerfile
FROM ubuntu:14.04
然后:
$ docker build -t test-image-without-volume .
$ docker run -ti test-image-without-volume bash
/# cd /hello
bash: cd: /hello: No such file or directory
/# exit
$ docker run -ti --volumes-from test-image-with-volume test-image-without-volume bash
/# cd /hello
total 8
drwxr-xr-x 2 root root 4096 Jan 18 14:59 ./
drwxr-xr-x 22 root root 4096 Jan 18 14:59 ../
/# touch test
然后在你原来的终端:
/# ls -la /hello
total 8
drwxr-xr-x 2 root root 4096 Jan 18 15:04 .
drwxr-xr-x 22 root root 4096 Jan 18 15:03 ..
-rw-r--r-- 1 root root 0 Jan 18 15:04 test
在您的新终端中:
/# ls -la /hello
total 8
drwxr-xr-x 2 root root 4096 Jan 18 15:04 .
drwxr-xr-x 22 root root 4096 Jan 18 15:03 ..
-rw-r--r-- 1 root root 0 Jan 18 15:04 test
您只能在包含卷的容器仍在运行时将卷从一个容器链接到另一个容器。