Docker中的Docker无法挂载卷 [英] Docker in Docker cannot mount volume
问题描述
我正在运行一个Jenkins集群,其中在Master和Slave中,它们都作为Docker容器运行.
I am running a Jenkins cluster where in the Master and Slave, both are running as a Docker containers.
主机是在MacOS上运行的最新的boot2docker VM.
The Host is latest boot2docker VM running on MacOS.
为了允许Jenkins能够使用Docker执行部署,我将docker.sock和docker客户端从主机安装到Jenkins容器,如下所示:-
To allow Jenkins to be able to perform deployment using Docker, I have mounted the docker.sock and docker client from the host to the Jenkins container like this :-
docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -v $HOST_JENKINS_DATA_DIRECTORY/jenkins_data:/var/jenkins_home -v $HOST_SSH_KEYS_DIRECTORY/.ssh/:/var/jenkins_home/.ssh/ -p 8080:8080 jenkins
在将卷装载到Jenkins容器中运行的Docker容器时遇到了问题.例如,如果需要在Jenkins容器中运行另一个Container,请执行以下操作:-
I am facing issues while mounting a volume to Docker containers that are run inside the Jenkins container. For example, if I need to run another Container inside the Jenkins container, I do the following :-
sudo docker run -v $JENKINS_CONTAINER/deploy.json:/root/deploy.json $CONTAINER_REPO/$CONTAINER_IMAGE
以上运行容器,但是文件"deploy.json"不是作为文件挂载,而是作为目录"挂载.即使将目录安装为卷,也无法查看生成的容器中的文件.
The above runs the container, but the file "deploy.json" is NOT mounted as a file, but instead as a "Directory". Even if I mount a Directory as a Volume, I am unable to view the files in the resulting container.
这是一个问题,因为在Docker情况下,由于Docker导致的文件权限吗?
Is this a problem, because of file permissions due to Docker in Docker case?
推荐答案
Docker容器中的Docker容器使用父HOST的Docker守护程序,因此,在"docker-in-docker"案例中挂载的所有卷仍从主机而不是从容器引用.
A Docker container in a Docker container uses the parent HOST's Docker daemon and hence, any volumes that are mounted in the "docker-in-docker" case is still referenced from the HOST, and not from the Container.
因此,在主机中从Jenkins容器安装的实际路径不存在".因此,将在空的"docker-in-docker"容器中创建一个新目录.将目录挂载到Container内的新Docker容器时,同样的情况也适用.
Therefore, the actual path mounted from the Jenkins container "does not exist" in the HOST. Due to this, a new directory is created in the "docker-in-docker" container that is empty. Same thing applies when a directory is mounted to a new Docker container inside a Container.
我错过了非常基本且显而易见的内容,但是我一输入问题就意识到了.
Very basic and obvious thing which I missed, but realized as soon I typed the question.
这篇关于Docker中的Docker无法挂载卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!