使用docker executor运行gitlab ci cd时,在本地系统上安装并运行docker是否重要?

yhuiod9q  于 2023-03-22  发布在  Docker
关注(0)|答案(1)|浏览(163)

我有一个上面提到的基本问题。为什么我有这个查询,因为当我运行CI/CD时,当docker不在我的本地运行时,它会显示这个错误。我可以知道这个问题的答案吗?另外,如果它不是强制性的,有人能告诉我应该解决这个问题吗?
我得到的错误:

Running with gitlab-runner 15.4.0 (43b2dc3d)
on runner3-dockerlatest pbSCcuw5
Preparing the "docker" executor
00:09
ERROR: Failed to remove network for build
ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (docker.go:863:0s)
Will be retried in 3s ...
ERROR: Failed to remove network for build
ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (docker.go:863:0s)
Will be retried in 3s ...
ERROR: Failed to remove network for build
ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (docker.go:863:0s)
Will be retried in 3s ...
ERROR: Job failed (system failure): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (docker.go:863:0s)
tp5buhyn

tp5buhyn1#

您的GitLab runner无法访问unix:///var/run/docker.sock。当您将runner注册为docker executer时,请添加此选项--docker-volumes='/var/run/docker.sock:/var/run/docker.sock'示例:

gitlab-runner register \
--non-interactive \
--url "https://gitlab.com/" \
--registration-token "your_token" \
--executor "docker" \
--docker-image docker:20.10.20 \
--docker-tlsverify="false" \
--docker-privileged="false" \
--docker-volumes='/var/run/docker.sock:/var/run/docker.sock' \
--docker-volumes='/cache' \
--description "My runner" \
--tag-list "docker.sock,imac" \
--run-untagged="false" \
--locked="false" \
--access-level="not_protected"

如果您的runner使用docker,不要忘记将/var/run/docker.sock从主机挂载到容器中:

docker run -d --name gitlab-runner --restart always \
  -v /var/run/docker.sock:/var/run/docker.sock \
  gitlab/gitlab-runner:latest

相关问题