Gitlab-runner 在 Docker 中使用 CI/CD DIND 出现错误

huangapple go评论71阅读模式
英文:

Gitlab-runner in docker with ci/cd dind error

问题

无法连接到位于服务器内部 Docker 上运行的 GitLab Runner。该 GitLab Runner 已成功注册到我的 GitLab。但是,当我运行 CI/CD 时出现错误:

错误: 无法连接到 Docker 守护程序,地址为 tcp://docker:2375。Docker 守护程序是否正在运行?

错误信息在此

我的 CI 文件任务

我用于 GitLab Runner 的 config.toml 文件

请告诉我如何修复这个错误。

我已经多次重新创建了 GitLab Runner 并重新创建了 CI 文件,但都没有成功。我是这样创建 GitLab Runner 的 -

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

然后进入 Docker 内部,我运行了以下命令 -

gitlab-runner register --url https://gitlab.com --token <my_token>

在 CI/CD 管道日志中:

准备 "docker" 执行器
00:17
使用带有 docker:git 镜像的 Docker 执行器...
启动 docker:dind 服务...
拉取 docker:dind 镜像...
使用带有 digest docker@sha256:5edfe3067bdd8b76818b036d8ef61846696af4d458ba527356c5484fcd692c2a 的 docker:dind 镜像...
等待服务启动并运行(超时时间为 30 秒)...
拉取 docker:git 镜像...
使用带有 digest docker@sha256:e86452c5f015fafa3957fa4cf7a38ac4b091a317fc0481f00f36dae6d8b065af 的 docker:git 镜像...
准备环境
00:02
正在通过 Git 存储库获取源代码
00:06
使用 git 深度设置为 20 获取更改...
在 /builds/<road>/.git/ 中重新初始化现有的 Git 存储库
以分离的 HEAD(引用为 develop)检出 a64f955b...
跳过 Git 子模块设置
执行作业脚本的 "step_script" 阶段
00:04
使用带有 digest docker@sha256:e86452c5f015fafa3957fa4cf7a38ac4b091a317fc0481f00f36dae6d8b065af 的 docker:git 镜像...
$ echo "正在运行发布状态"
正在运行发布状态
$ docker build -t $TAG_LATEST .
错误: 无法连接到 Docker 守护程序,地址为 tcp://docker:2375。Docker 守护程序是否正在运行?
英文:

I have gitlab-runner running inside the docker on my server. This gitlab-runner is successfully registered for my gitlab.
But when I run ci/cd I get an error:

ERROR: Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?

error here

my ci file task

my config.toml file for gitlab-runner

Please tell me how to fix this error.

I've already recreated gitlab-runner and redid the ci file several times. Nothing worked. I created gitlab-runner with the command -

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

Then going into the docker itself I ran the command -

gitlab-runner register --url https://gitlab.com --token &lt;my_token&gt;

In CI/CD Pipeline log

Preparing the &quot;docker&quot; executor
00:17
Using Docker executor with image docker:git ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image sha256:881c987bf80d40ddcc0f01d845242611380eba9115d9eeab12713c5215c21959 for docker:dind with digest docker@sha256:5edfe3067bdd8b76818b036d8ef61846696af4d458ba527356c5484fcd692c2a ...
Waiting for services to be up and running (timeout 30 seconds)...
Pulling docker image docker:git ...
Using docker image sha256:fce9ca002cbb40452df4ab64ec9b726fd1ba7fbc2eb3b4b482da87f6013541b5 for docker:git with digest docker@sha256:e86452c5f015fafa3957fa4cf7a38ac4b091a317fc0481f00f36dae6d8b065af ...
Preparing environment
00:02
Running on &lt;runner_info&gt; via 428a77e8bbfe...
Getting source from Git repository
00:06
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /builds/&lt;road&gt;/.git/
Checking out a64f955b as detached HEAD (ref is develop)...
Skipping Git submodules setup
Executing &quot;step_script&quot; stage of the job script
00:04
Using docker image sha256:fce9ca002cbb40452df4ab64ec9b726fd1ba7fbc2eb3b4b482da87f6013541b5 for docker:git with digest docker@sha256:e86452c5f015fafa3957fa4cf7a38ac4b091a317fc0481f00f36dae6d8b065af ...
$ echo &quot;running publish state&quot;
running publish state
$ docker build -t $TAG_LATEST .
ERROR: Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?

答案1

得分: 0

当您使用docker run来启动您的runner时,您还需要传递--privileged标志。

docker run --privileged ...

您可能还需要在作业中设置变量DOCKER_HOSTDOCKER_TLS_CERTDIR

myjob:
  # ...
  variables:
    DOCKER_HOST: "tcp://docker:2375"
    DOCKER_TLS_CERTDIR: ""
英文:

When you do docker run to start your runner, you also need to pass the --privileged flag.

docker run --privileged ...

You may also need to set the variables DOCKER_HOST and DOCKER_TLS_CERTDIR in your job.

myjob:
  # ...
  variables:
    DOCKER_HOST: &quot;tcp://docker:2375&quot;
    DOCKER_TLS_CERTDIR: &quot;&quot;

huangapple
  • 本文由 发表于 2023年6月9日 02:36:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76434796.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定