Gitlab 亚军 - tcp://localhost:2375。 docker 守护进程是 运行 吗?
GitlabRunner - tcp://localhost:2375. Is the docker daemon running?
我正在尝试在 EC2 上安装 gitlab-运行ner。我想要的执行者是 Docker.
我的config.toml是
concurrent = 10
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "My Docker Runner"
url = "https://gitlab.com/"
token = "SECRET"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "docker:19.03.12"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/certs/client", "/cache"]
shm_size = 0
我的.gitlab-ci.yml是
image: docker:19.03.12
variables:
# When you use the dind service, you must instruct Docker to talk with
# the daemon started inside of the service. The daemon is available
# with a network connection instead of the default
# /var/run/docker.sock socket. Docker 19.03 does this automatically
# by setting the DOCKER_HOST in
# https://github.com/docker-library/docker/blob/d45051476babc297257df490d22cbd806f1b11e4/19.03/docker-entrypoint.sh#L23-L29
#
# The 'docker' hostname is the alias of the service container as described at
# https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services.
#
# Specify to Docker where to create the certificates. Docker
# creates them automatically on boot, and creates
# `/certs/client` to share between the service and job
# container, thanks to volume mount from config.toml
DOCKER_TLS_CERTDIR: "/certs"
services:
- docker:19.03.12-dind
before_script:
- docker info
build:
stage: build
script:
- docker build -t my-docker-image .
- docker run my-docker-image /script/to/run/tests
我总是遇到这个错误:
Running with gitlab-runner 14.4.0 (4b9e985a)
on My Docker Runner u9_6MpHg
Resolving secrets
00:00
Preparing the "docker" executor
Using Docker executor with image docker:19.03.12 ...
Starting service docker:19.03.12-dind ...
Authenticating with credentials from $DOCKER_AUTH_CONFIG
Pulling docker image docker:19.03.12-dind ...
Using docker image sha256:66dc2d45749a48592f4348fb3d567bdd65c9dbd5402a413b6d169619e32f6bd2 for docker:19.03.12-dind with digest docker@sha256:674f1f40ff7c8ac14f5d8b6b28d8fb1f182647ff75304d018003f1e21a0d8771 ...
Waiting for services to be up and running...
Authenticating with credentials from $DOCKER_AUTH_CONFIG
Pulling docker image docker:19.03.12 ...
Using docker image sha256:81f5749c9058a7284e6acd8e126f2b882765a17b9ead14422b51cde1a110b85c for docker:19.03.12 with digest docker@sha256:d41efe7ad0df5a709cfd4e627c7e45104f39bbc08b1b40d7fb718c562b3ce135 ...
Preparing environment
00:00
Running on runner-u96mphg-project-31310309-concurrent-0 via ip-10-120-65-72.ec2.internal...
Getting source from Git repository
00:02
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/mediagrif/itt/network/poc/test-private-runner/.git/
Created fresh repository.
Checking out 3d7fe999 as main...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:01
Using docker image sha256:81f5749c9058a7284e6acd8e126f2b882765a17b9ead14422b51cde1a110b85c for docker:19.03.12 with digest docker@sha256:d41efe7ad0df5a709cfd4e627c7e45104f39bbc08b1b40d7fb718c562b3ce135 ...
$ docker info
Client:
Debug Mode: false
Server:
**ERROR: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?**
errors pretty printing info
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1
我尝试了一整天并按照 gitlab 文档中的所有说明进行操作,但没有任何效果。我总是遇到同样的错误。我尝试使用 shell 执行器、docker 和 docker+ 机器执行器,但我有同样的错误。
我尝试使用 DinD、直接 Socket 和 Shell 执行器来构建我的 Docker 图像。
我试图 specify DOCKER_HOST,服务别名,禁用证书。
我发现奇怪的是,即使我在我的 gitlab-ci 中更改了 DOCKER_HOST,当我查看 /etc/hosts 时,我看到了该服务的记录,但是错误消息始终指向本地主机。
我尝试使用 Gitlab Runner 13.11.0 和 14.4.0 版本。我尝试用 YUM 安装 运行ner。我还尝试用 Docker 运行 运行 它。我还在我的 gitlab-ci 文件中尝试使用 Docker 19 和 Docker 20.
没有任何效果。
请问有人给我提示吗?
谢谢
颜
这里可能会发生几件事情,但听起来您已经尝试了基本的 DOCKER_HOST 事情。通常,DinD 会将主机设置为必要的,因此 DinD 连接到主机上的 docker 守护程序时会出现一些问题。这里有几件事可以尝试:
- SSH 进入您的 GitLab 运行ner,并 运行
docker ps
以确保套接字 运行ning 正确。启动时可能未将套接字设置为 运行。
- 当您通过 SSH 连接到您的盒子时,请确保您可以在不使用
sudo
的情况下访问 docker。如果你的gitlab-运行ner用户需要使用sudo
访问docker,就会报错
- 在您的 运行ner 盒子上启动一个 DinD 容器,传递特权标志,并尝试从 DinD 容器内访问 docker。
很有可能错误是 docker 在主机上的配置方式 - 您的 运行ner toml 或 CI yml 看起来没有问题。
两件事:
使用 docker:dind
服务时,docker 守护程序的主机名是 docker
而不是 localhost
。 GitLab 文档在这里有点自相矛盾。
虽然 docker:19.03.12
图像确实正确设置了 docker 主机,但在某些情况下,您有时会 做 (例如 Kubernetes 执行器的情况)和其他情况)需要指定 DOCKER_HOST
为了 dind 容器本身的利益。
另外,当指定DOCKER_TLS_CERTDIR
时,默认启用TLS,启用TLS的监听端口是2376
而不是2375
。
要更正此问题,请进行以下任一配置更改:
variables:
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_HOST: "tcp://docker:2376" # dind with TLS enabled
或
varaibles:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: "tcp://docker:2375" # dind with TLS disabled
您还应该仔细检查您的证书目录是否确实包含正确的证书或挂载点是否可写,否则 if the certs are missing, dind treats it as if TLS is disabled.
如果你的工作似乎使用 localhost:2375
尽管你的环境变量,那一定是因为这个变量在某处被覆盖,比如在项目或组级别设置 CI/CD 设置,这将覆盖您的 YAML 配置。
您可以通过回显以下值在您的作业脚本中确认这一点:
script:
- echo $DOCKER_HOST
- docker info
我正在尝试在 EC2 上安装 gitlab-运行ner。我想要的执行者是 Docker.
我的config.toml是
concurrent = 10
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "My Docker Runner"
url = "https://gitlab.com/"
token = "SECRET"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "docker:19.03.12"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/certs/client", "/cache"]
shm_size = 0
我的.gitlab-ci.yml是
image: docker:19.03.12
variables:
# When you use the dind service, you must instruct Docker to talk with
# the daemon started inside of the service. The daemon is available
# with a network connection instead of the default
# /var/run/docker.sock socket. Docker 19.03 does this automatically
# by setting the DOCKER_HOST in
# https://github.com/docker-library/docker/blob/d45051476babc297257df490d22cbd806f1b11e4/19.03/docker-entrypoint.sh#L23-L29
#
# The 'docker' hostname is the alias of the service container as described at
# https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services.
#
# Specify to Docker where to create the certificates. Docker
# creates them automatically on boot, and creates
# `/certs/client` to share between the service and job
# container, thanks to volume mount from config.toml
DOCKER_TLS_CERTDIR: "/certs"
services:
- docker:19.03.12-dind
before_script:
- docker info
build:
stage: build
script:
- docker build -t my-docker-image .
- docker run my-docker-image /script/to/run/tests
我总是遇到这个错误:
Running with gitlab-runner 14.4.0 (4b9e985a)
on My Docker Runner u9_6MpHg
Resolving secrets
00:00
Preparing the "docker" executor
Using Docker executor with image docker:19.03.12 ...
Starting service docker:19.03.12-dind ...
Authenticating with credentials from $DOCKER_AUTH_CONFIG
Pulling docker image docker:19.03.12-dind ...
Using docker image sha256:66dc2d45749a48592f4348fb3d567bdd65c9dbd5402a413b6d169619e32f6bd2 for docker:19.03.12-dind with digest docker@sha256:674f1f40ff7c8ac14f5d8b6b28d8fb1f182647ff75304d018003f1e21a0d8771 ...
Waiting for services to be up and running...
Authenticating with credentials from $DOCKER_AUTH_CONFIG
Pulling docker image docker:19.03.12 ...
Using docker image sha256:81f5749c9058a7284e6acd8e126f2b882765a17b9ead14422b51cde1a110b85c for docker:19.03.12 with digest docker@sha256:d41efe7ad0df5a709cfd4e627c7e45104f39bbc08b1b40d7fb718c562b3ce135 ...
Preparing environment
00:00
Running on runner-u96mphg-project-31310309-concurrent-0 via ip-10-120-65-72.ec2.internal...
Getting source from Git repository
00:02
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/mediagrif/itt/network/poc/test-private-runner/.git/
Created fresh repository.
Checking out 3d7fe999 as main...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:01
Using docker image sha256:81f5749c9058a7284e6acd8e126f2b882765a17b9ead14422b51cde1a110b85c for docker:19.03.12 with digest docker@sha256:d41efe7ad0df5a709cfd4e627c7e45104f39bbc08b1b40d7fb718c562b3ce135 ...
$ docker info
Client:
Debug Mode: false
Server:
**ERROR: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?**
errors pretty printing info
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1
我尝试了一整天并按照 gitlab 文档中的所有说明进行操作,但没有任何效果。我总是遇到同样的错误。我尝试使用 shell 执行器、docker 和 docker+ 机器执行器,但我有同样的错误。
我尝试使用 DinD、直接 Socket 和 Shell 执行器来构建我的 Docker 图像。
我试图 specify DOCKER_HOST,服务别名,禁用证书。
我发现奇怪的是,即使我在我的 gitlab-ci 中更改了 DOCKER_HOST,当我查看 /etc/hosts 时,我看到了该服务的记录,但是错误消息始终指向本地主机。
我尝试使用 Gitlab Runner 13.11.0 和 14.4.0 版本。我尝试用 YUM 安装 运行ner。我还尝试用 Docker 运行 运行 它。我还在我的 gitlab-ci 文件中尝试使用 Docker 19 和 Docker 20.
没有任何效果。
请问有人给我提示吗?
谢谢
颜
这里可能会发生几件事情,但听起来您已经尝试了基本的 DOCKER_HOST 事情。通常,DinD 会将主机设置为必要的,因此 DinD 连接到主机上的 docker 守护程序时会出现一些问题。这里有几件事可以尝试:
- SSH 进入您的 GitLab 运行ner,并 运行
docker ps
以确保套接字 运行ning 正确。启动时可能未将套接字设置为 运行。 - 当您通过 SSH 连接到您的盒子时,请确保您可以在不使用
sudo
的情况下访问 docker。如果你的gitlab-运行ner用户需要使用sudo
访问docker,就会报错 - 在您的 运行ner 盒子上启动一个 DinD 容器,传递特权标志,并尝试从 DinD 容器内访问 docker。
很有可能错误是 docker 在主机上的配置方式 - 您的 运行ner toml 或 CI yml 看起来没有问题。
两件事:
使用 docker:dind
服务时,docker 守护程序的主机名是 docker
而不是 localhost
。 GitLab 文档在这里有点自相矛盾。
虽然 docker:19.03.12
图像确实正确设置了 docker 主机,但在某些情况下,您有时会 做 (例如 Kubernetes 执行器的情况)和其他情况)需要指定 DOCKER_HOST
为了 dind 容器本身的利益。
另外,当指定DOCKER_TLS_CERTDIR
时,默认启用TLS,启用TLS的监听端口是2376
而不是2375
。
要更正此问题,请进行以下任一配置更改:
variables:
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_HOST: "tcp://docker:2376" # dind with TLS enabled
或
varaibles:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: "tcp://docker:2375" # dind with TLS disabled
您还应该仔细检查您的证书目录是否确实包含正确的证书或挂载点是否可写,否则 if the certs are missing, dind treats it as if TLS is disabled.
如果你的工作似乎使用 localhost:2375
尽管你的环境变量,那一定是因为这个变量在某处被覆盖,比如在项目或组级别设置 CI/CD 设置,这将覆盖您的 YAML 配置。
您可以通过回显以下值在您的作业脚本中确认这一点:
script:
- echo $DOCKER_HOST
- docker info