簡體   English   中英

如何讓 docker 在作為容器的 Jenkins 節點中運行?

[英]How can I get docker running in Jenkins nodes which are containers?

我試圖讓 docker 在 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從節點文件系統掛載路徑,所以如果我理解正確,這不是你想要實現的。 恐怕不可能將單個文件掛載為一個卷,所以即使你從volumes刪除hostPathdocker.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 守護進程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM