![](/img/trans.png)
[英]“Cannot connect to the Docker daemon.” error while building docker image in gitlab-ci docker executor
[英]GitLab CI - Cannot connect to the Docker daemon from within an image
我有一個基於節點的項目,以下是作為構建的一部分需要執行的前幾個步驟:
npm install
npm run build
docker build -t client .
上面的最后一個命令構建了以下 Dockerfile:
FROM docker.artifactory.abc.net/nginx
COPY build /usr/share/nginx/html
COPY default.conf /etc/nginx/conf.d/default.conf
.gitlab-ci.yml
內容:
image: docker.artifactory.abc.net/docker/node:1.0
stages:
- build
- deploy
build:
stage: build
script:
- npm install
- npm run build
- docker build -t client .
在上面的 Dockerfile 中,我使用了一個自定義節點映像 ( node:1.0
),其中包含apk
工作的代理設置和 Artifactory 配置,因此所有依賴項都是使用 Artifactory 獲取的。 現在,當我運行這個構建時,我在執行最后一個命令( docker build -t client .
)時收到docker: command not found
錯誤,這是預期的,因為基本映像用於node
並且不包含docker
。 因此,我根據此鏈接向節點 Dockerfile 添加了 docker 設置說明,除了最后 3 行配置 ENTRYPOINT 和 CMD。
現在,當我運行構建時,我得到了:
$ docker build -t client .
Sending build context to Docker daemon 372.7MB
Step 1 : FROM docker.artifactory.abc.net/nginx
Get https://docker.artifactory.abc.net/v2/nginx/manifests/latest: unknown: Authentication is required
ERROR: Job failed: exit code 1
根據我過去的經驗,這個錯誤與運行docker login
命令有關。 由於官方鏡像中的 docker 設置使用 tar,因此我必須將docker
用戶添加到/etc/group
,然后將當前用戶(root)添加到docker
組。 還在 Dockerfile 中添加了如下所示的 docker docker login
命令:
addgroup docker; \
adduser root docker; \
docker login docker.artifactory.abc.net -u svc-art -p "ZTg6#&kq"; \
之后,如果我嘗試構建此 Dockerfile,則會出現以下錯誤:
+ dockerd -v
Docker version 17.05.0-ce, build v17.05.0-ce
+ docker -v
Docker version 17.05.0-ce, build v17.05.0-ce
+ adduser root docker
+ tail -2 /etc/group
node:x:1000:node
docker:x:101:root
+ docker login docker.artifactory.abc.net -u svc-art -p ZTg6#&kq
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
我還做了一個ls -ltr /var/run/docker.sock;
和泊塢窗套接字文件不存在在圖像內。 這似乎是問題所在。
知道如何讓這個工作嗎?
好吧,從您提供的示例中,我看不到您在哪里調用 docker 服務,因此我假設您沒有調用它,也沒有登錄到注冊表。
您的管道應如下所示:
image: docker.artifactory.abc.net/docker/node:1.0
stages:
- build
- deploy
build:
image: docker:latest
services:
- docker:dind
stage: build
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.example.com
- docker build -t registry.example.com/group/project/image:latest .
- docker push registry.example.com/group/project/image:latest
你也可以在這里找到更多信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.