我正在尝试让docker在Jenkins上运行,Jenkins本身就是一个容器。下面是Pod规范的一部分。
cyrilpanicker/jenkins是一个安装了Jenkins和docker-cli的镜像。对于Docker守护进程,我正在运行另一个带有docker:dind镜像的容器(节点运行在k8s集群上)。为了在它们之间连接docker.sock,我使用了卷挂载。
spec:
containers:
- name: jenkins
image: cyrilpanicker/jenkins
volumeMounts:
- mountPath: /var/run/docker.sock
name: docker-socket
- name: docker
image: docker:dind
securityContext:
privileged: true
volumeMounts:
- mountPath: /var/run/docker.sock
name: docker-socket
volumes:
- name: docker-socket
hostPath:
path: /docker.sock
type: FileOrCreate但这是行不通的。下面是来自docker容器的日志。
time="2021-06-04T20:47:26.059792967Z" level=info msg="Starting up"
time="2021-06-04T20:47:26.061956820Z" level=warning msg="could not change group /var/run/docker.sock to docker: group docker not found"
failed to load listeners: can't create unix socket /var/run/docker.sock: device or resource busy有没有人能提出另一种方法来解决这个问题呢?
发布于 2021-06-05 22:56:00
根据kubernetes文档,hostPath从节点文件系统挂载路径,所以如果我理解正确的话,这不是您想要实现的目标。恐怕不可能将单个文件作为卷挂载,所以即使您从volumes中移除hostPath,docker.sock也会挂载为目录:
jenkins@static-web:/$ ls -la /var/run/
total 20
drwxr-xr-x 1 root root 4096 Jun 5 14:44 .
drwxr-xr-x 1 root root 4096 Jun 5 14:44 ..
drwxrwxrwx 2 root root 4096 Jun 5 14:44 docker.sock我会尝试在dind容器中使用TCP侦听器而不是sock文件运行docker守护进程:
spec:
containers:
- name: jenkins
image: cyrilpanicker/jenkins
- name: docker
image: docker:dind
command: ["dockerd"]
args: ["-H", "tcp://127.0.0.1:2376"]
ports:
- containerPort: 2376
securityContext:
privileged: truejenkins@static-web:/$ docker -H tcp://127.0.0.1:2376 ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES然后将jenkins配置为使用tcp://127.0.0.1:2376作为远程docker守护进程。
https://stackoverflow.com/questions/67843919
复制相似问题