如何将容器目录挂载到另一个Docker容器? [英] How to mount container directory to another docker container?
问题描述
我有以下配置:
- 主机:ubuntu,正在运行docker服务器,并且在
/home/apps/
中具有应用程序目录. - Container-A:docker:latest,
-v/home/apps:/apps -v/var/run/docker.sock:/var/run/docker.sock
,现在有了/apps
中的应用. - 容器B:python:2.7,
-v/apps/foo:/foo
,/foo
中的一个特定应用.
Container-A使用 docker run
运行Container-B,我需要将/apps/foo
挂载到Container-B的/foo
.但是不会,/foo
为空.
我相信这是因为docker服务器正在其他地方(在Container-A之外)运行.
将/apps/foo
挂载到Container-B的方式是什么?
Container-A正在使用标志 -v/apps -v/var/run/docker.sock:/var/run/docker.sock
运行.未从主机上安装/apps
.在这种情况下,如何将/apps/foo
挂载到Container-B?
那是正确的.由于您使用的是/var/run/docker.sock,即使您从Container-A运行 -v/apps/foo:/foo
,主机仍然是您的docker服务器运行的主机.
因此,您可以像这样创建一个卷: -v/home/apps/foo:/foo
(从Container-A内)或在Container-A内设置辅助docker服务器./p>
I have following configuration:
- Host: ubuntu, has docker server running, has directories of apps in
/home/apps/
. - Container-A: docker:latest,
-v /home/apps:/apps -v /var/run/docker.sock:/var/run/docker.sock
, now it has apps in/apps
. - Container-B: python:2.7,
-v /apps/foo:/foo
, one specific app in/foo
.
Container-A runs Container-B using docker run
and I need /apps/foo
to be mounted to Container-B's /foo
. But it won't, /foo
is empty.
I believe it's because docker server is running somewhere else (outside of Container-A).
What are the ways of mounting /apps/foo
to Container-B?
EDIT:
Container-A is running with flags -v /apps -v /var/run/docker.sock:/var/run/docker.sock
. /apps
is not mounted from the host. How to mount /apps/foo
to Container-B in this case?
That is correct.
Since you are using /var/run/docker.sock, even when you run -v /apps/foo:/foo
from Container-A, the host machine is still the one your docker server runs on.
So you can either create a volume like that: -v /home/apps/foo:/foo
(from inside Container-A) or setup a secondary docker server inside Container-A.
这篇关于如何将容器目录挂载到另一个Docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!