如何解决如何让 docker 在作为容器的 Jenkins 节点中运行?
我试图让 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
有人可以建议另一种方法来让这个工作吗?
解决方法
根据 kubernetes 文档,hostPath
从节点文件系统挂载一个路径,所以如果我理解正确的话,这不是您想要实现的。
恐怕无法将单个文件挂载为卷,因此即使您从 hostPath
中删除 volumes
,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
我会尝试使用 TCP 侦听器而不是 sock 文件在 dind 容器中运行 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: true
jenkins@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 守护进程。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。