Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让docker在Jenkins节点(容器)中运行?_Docker_Jenkins_Kubernetes_Dind - Fatal编程技术网

如何让docker在Jenkins节点(容器)中运行?

如何让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

我试图让docker在Jenkins上运行,Jenkins本身就是一个容器。以下是Pod规范的一部分

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文件中