Docker 中的 Docker 无法挂载卷 [英] Docker in Docker cannot mount volume

查看:83
本文介绍了Docker 中的 Docker 无法挂载卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个 Jenkins 集群,其中主节点和从节点都作为 Docker 容器运行.

I am running a Jenkins cluster where in the Master and Slave, both are running as a Docker containers.

Host 是在 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 容器内运行另一个容器,我会执行以下操作:-

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"情况下安装的任何卷仍然是从 HOST 引用,而不是从容器引用.

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 容器挂载的实际路径在 HOST 中不存在".因此,在空的docker-in-docker"容器中创建了一个新目录.当目录被挂载到容器内的新 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆