无法连接到 tcp://localhost:2375/ 上的 Docker 守护程序。 docker 守护进程是不是正在运行。在 GitLab 上
Posted
技术标签:
【中文标题】无法连接到 tcp://localhost:2375/ 上的 Docker 守护程序。 docker 守护进程是不是正在运行。在 GitLab 上【英文标题】:Cannot connect to the Docker daemon at tcp://localhost:2375/. Is the docker daemon running. On GitLab无法连接到 tcp://localhost:2375/ 上的 Docker 守护程序。 docker 守护进程是否正在运行。在 GitLab 上 【发布时间】:2020-07-21 03:20:06 【问题描述】:我正在尝试在 GitLab 中构建 CI 管道。我想问一下在 GitLab CI 中工作的 docker。
来自这个问题:https://gitlab.com/gitlab-org/gitlab-runner/issues/4501#note_195033385
两种方式我都遵循说明。使用 TLS 而未使用 TLS。 但它仍然卡住了。同样的错误
无法连接到位于 tcp://localhost:2375/ 的 Docker 守护程序。 docker 守护进程是否正在运行
我已尝试解决此问题。跟着下面,
1) 启用 TLS
其中使用 .gitlab-ci.yml 和 config.toml 在 Runner 中启用 TLS。
这是我的 .gitlab-ci.yml
image: docker:19.03
variables:
DOCKER_HOST: tcp://localhost:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_NAME: image_name
services:
- docker:19.03-dind
stages:
- build
publish:
stage: build
script:
- docker build -t$IMAGE_NAME:$(echo $CI_COMMIT_SHA | cut -c1-10) .
- docker push $IMAGE_NAME:$(echo $CI_COMMIT_SHA | cut -c1-10)
only:
- master
这是我的 config.toml
[[runners]]
name = MY_RUNNER
url = MY_HOST
token = MY_TOKEN_RUNNER
executor = "docker"
[runners.custom_build_dir]
[runners.docker]
tls_verify = false
image = "docker:stable"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/certs/client", "/cache"]
shm_size = 0
2) 禁用 TLS
.gitlab-ci.yml
image: docker:18.09
variables:
DOCKER_HOST: tcp://localhost:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
IMAGE_NAME: image_name
services:
- docker:18.09-dind
stages:
- build
publish:
stage: build
script:
- docker build -t$IMAGE_NAME:$(echo $CI_COMMIT_SHA | cut -c1-10) .
- docker push $IMAGE_NAME:$(echo $CI_COMMIT_SHA | cut -c1-10)
only:
- master
这是我的 config.toml
[[runners]]
environment = ["DOCKER_TLS_CERTDIR="]
有人知道吗?
【问题讨论】:
【参考方案1】:您想将DOCKER_HOST
设置为tcp://docker:2375
。它是一个“服务”,即运行在一个单独的容器中,默认以镜像名称命名,而不是本地主机。
这是一个应该可以工作的.gitlab-ci.yml
sn-p:
# Build and push the Docker image off of merges to master; based off
# of Gitlab CI support in https://pythonspeed.com/products/pythoncontainer/
docker-build:
stage: build
image:
# An alpine-based image with the `docker` CLI installed.
name: docker:stable
# This will run a Docker daemon in a container (Docker-In-Docker), which will
# be available at thedockerhost:2375. If you make e.g. port 5000 public in Docker
# (`docker run -p 5000:5000 yourimage`) it will be exposed at thedockerhost:5000.
services:
- name: docker:dind
alias: thedockerhost
variables:
# Tell docker CLI how to talk to Docker daemon; see
# https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker-executor
DOCKER_HOST: tcp://thedockerhost:2375/
# Use the overlayfs driver for improved performance:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
script:
# Download bash:
- apk add --no-cache bash python3
# GitLab has a built-in Docker image registry, whose parameters are set automatically.
# See https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#using-the-gitlab-contai
#
# CHANGEME: You can use some other Docker registry though by changing the
# login and image name.
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
- docker build -t "$CI_REGISTRY_IMAGE" .
- docker push "$CI_REGISTRY_IMAGE"
# Only build off of master branch:
only:
- master
【讨论】:
还是不行error during connect: Get http://docker:2375/v1.39/containers/json?all=1: dial tcp: lookup docker on xxx.xxx.xxx.xxx:53: no such host
哪个运行CI,禁用TLS。
哦,我发现了实际问题。这与码头工人无关。只是我的服务器不允许 GitLab runner 和 docker。我将 GitLab 与自托管一起使用。所以现在它成功了!!。
对这个答案的许多赞誉。
我也有同样的问题,按照上面的代码修改后
@zzob 你能描述一下,你设置了哪个权限或者你用 sudo 运行了哪个进程?以上是关于无法连接到 tcp://localhost:2375/ 上的 Docker 守护程序。 docker 守护进程是不是正在运行。在 GitLab 上的主要内容,如果未能解决你的问题,请参考以下文章
无法使用php连接错误连接到mysql:无法连接到'localhost'(10061)上的MySQL服务器[重复]
MySQL Workbench 无法连接到我的 RDS 数据库:无法连接到 localhost
Django docker 容器无法连接到 mysql 容器,出现错误“无法连接到 'db' (111) 上的 MySQL 服务器”)