英文:
Gitlab-runner in docker with ci/cd dind error
问题
无法连接到位于服务器内部 Docker 上运行的 GitLab Runner。该 GitLab Runner 已成功注册到我的 GitLab。但是,当我运行 CI/CD 时出现错误:
错误: 无法连接到 Docker 守护程序,地址为 tcp://docker:2375。Docker 守护程序是否正在运行?
我用于 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?
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 <my_token>
In CI/CD Pipeline log
Preparing the "docker" 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 <runner_info> via 428a77e8bbfe...
Getting source from Git repository
00:06
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /builds/<road>/.git/
Checking out a64f955b as detached HEAD (ref is develop)...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:04
Using docker image sha256:fce9ca002cbb40452df4ab64ec9b726fd1ba7fbc2eb3b4b482da87f6013541b5 for docker:git with digest docker@sha256:e86452c5f015fafa3957fa4cf7a38ac4b091a317fc0481f00f36dae6d8b065af ...
$ echo "running publish state"
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_HOST
和DOCKER_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: "tcp://docker:2375"
DOCKER_TLS_CERTDIR: ""
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论