如何让docker在Jenkins节点(容器)中运行?
我试图让docker在Jenkins上运行,Jenkins本身就是一个容器。以下是Pod规范的一部分如何让docker在Jenkins节点(容器)中运行?,docker,jenkins,kubernetes,dind,Docker,Jenkins,Kubernetes,Dind,我试图让docker在Jenkins上运行,Jenkins本身就是一个容器。以下是Pod规范的一部分 cyrilpanicker/jenkins是一个安装了jenkins和docker cli的映像。 对于Docker守护进程,我正在运行另一个带有Docker:dindimage的容器(节点在k8s集群上运行)。 为了在它们之间建立docker.sock链接,我使用了卷挂载 spec: containers: - name: jenkins image: cyrilpan
cyrilpanicker/jenkins
是一个安装了jenkins和docker cli的映像。
对于Docker守护进程,我正在运行另一个带有Docker:dind
image的容器(节点在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
从节点文件系统挂载路径,因此如果我理解正确,这不是您想要实现的。
恐怕无法将单个文件作为卷装载,因此即使从卷
中删除主机路径
,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使用
tcp://127.0.0.1:2376
作为远程docker守护进程。根据kubernetes文档,主机路径
从节点文件系统装载路径,因此如果我理解正确,这不是您想要实现的。
恐怕无法将单个文件作为卷装载,因此即使从卷
中删除主机路径
,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使用
tcp://127.0.0.1:2376
作为远程docker守护进程。您可以将单个文件装载为卷此解决方案有效。并且我能够使用docker.withServer('s)连接到远程docker守护进程tcp://127.0.0.1:2376“){}
在Jenkins文件中,您可以将单个文件作为卷装入此解决方案有效。并且我能够使用docker.withServer('s)连接到远程docker守护进程tcp://127.0.0.1:2376“){}
在Jenkins文件中