连接时出现Docker错误:发布http://docker:2375/v1.24/auth

hfyxw5xn  于 2023-04-11  发布在  Docker
关注(0)|答案(2)|浏览(325)

我正在使用docker+机器运行我的gitlab ci/cd作业。我的.gitlab-ci.yml看起来像这样:

image: docker:latest

variables:
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_TLS_CERTDIR: ""

services:
  - docker:19.03.12-dind

stages:
  - build
  - deploy

before_script:
  - mkdir -p ~/.ssh
  - echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
  - chmod 700 ~/.ssh/id_rsa
  - eval "$(ssh-agent -s)"
  - ssh-add ~/.ssh/id_rsa
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

build:
  stage: build
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD registry.gitlab.com
    - docker info
    - apk add --no-cache py-pip python3-dev libffi-dev openssl-dev gcc libc-dev make
    - export CRYPTOGRAPHY_DONT_BUILD_RUST=1
    - pip install docker-compose

我的config.toml看起来像这样:

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "Docker Runner"
  url = "https://gitlab.com"
  token = "**"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    shm_size = 0

到达命令时:“docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORDregistry.gitlab.com“GitLab输出如下:

$ [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
$ docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD registry.gitlab.com
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
error during connect: Post http://docker:2375/v1.24/auth: dial tcp: lookup docker on 172.31.0.2:53: no such host
Cleaning up file based variables 00:01
ERROR: Job failed: exit code 1

我不明白错误可能在哪里...在更改ci文件和config. toml之后。

hwamh0ep

hwamh0ep1#

我已经找到了解决我的错误的方法。
这只是runner和gitlab-ci文件之间的docker图像不匹配。我只是在yaml和toml文件中更改了image = docker:19.03.12

acruukt9

acruukt92#

我有类似的问题,只有当我为它添加alias时才能工作:

services:
    - name: docker:23.0.1-dind
      alias: docker

相关问题