Gitlab runner docker无法解析主机

前端之家收集整理的这篇文章主要介绍了Gitlab runner docker无法解析主机前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在我的Ubuntu OS上使用了2个容器:Gitlab-ce和gitlab-runner

容器名称为:gitlab_gitlab_1和gitlab_gitlab-runner_1

我通过gitlab.localhost.com:801访问我的gitlab应用程序

我用这个命令成功注册了一个跑步者:

docker exec -it gitlab_gitlab-runner_1 gitlab-runner register --non-interactive --url http://gitlab_gitlab_1 --registration-token _wgMgEx3nBocYQtoi83c --executor docker --docker-image alpine:latest

然后,当我开始工作时,我收到此错误消息:

Running with gitlab-runner 10.7.1 (b9bba623)
  on 589a617ee407 12ba77f7
Using Docker executor with image alpine:latest ...
Pulling docker image alpine:latest ...
Using docker image sha256:3fd9065eaf02feaf94d68376da52541925650b81698c53c6824d92ff63f98353 for alpine:latest ...
Running on runner-12ba77f7-project-1-concurrent-0 via 01196621a827...
Cloning repository...
Cloning into '/builds/root/test'...
fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.localhost.com/root/test.git/': Could not resolve host: gitlab.localhost.com
ERROR: Job Failed: exit code 1

在这两个容器中,我都可以访问主机名gitlab.localhost.com.
我认为这个问题来自高山图像无法解决主机问题.

我该如何解决这个问题?

谢谢

编辑1

泊坞窗,compose.yml

version: '3'
services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest'
    restart: always
    hostname: 'gitlab.localhost.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.localhost.com'
    ports:
      - '801:80'
      - '443:443'
      - '22:22'
    volumes:
      - '/srv/gitlab/config:/etc/gitlab'
      - '/srv/gitlab/logs:/var/log/gitlab'
      - '/srv/gitlab/data:/var/opt/gitlab'
    networks:
      - 'default'

  gitlab-runner:
    image: 'gitlab/gitlab-runner:latest'
    depends_on:
      - 'gitlab'
    restart: always
    volumes:
      - '/srv/gitlab-runner/config:/etc/gitlab-runner'
      - '/var/run/docker.sock:/var/run/docker.sock'
    networks:
      - 'default'
    links:
      - 'gitlab:gitlab.localhost.com'

networks:
  default:
    driver: 'bridge'

编辑2

泊坞窗,compose.yml

version: '3'
services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest'
    restart: always
    hostname: 'gitlab.localhost.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.localhost.com'
    ports:
      - '801:80'
      - '443:443'
      - '22:22'
    volumes:
      - '/srv/gitlab/config:/etc/gitlab'
      - '/srv/gitlab/logs:/var/log/gitlab'
      - '/srv/gitlab/data:/var/opt/gitlab'
    networks:
      default:
        aliases:
          - 'gitlab.localhost.com'

  gitlab-runner:
    image: 'gitlab/gitlab-runner:latest'
    depends_on:
      - 'gitlab'
    restart: always
    volumes:
      - '/srv/gitlab-runner/config:/etc/gitlab-runner'
      - '/var/run/docker.sock:/var/run/docker.sock'
    networks:
      - 'default'

networks:
  default:
    driver: 'bridge'
最佳答案
感谢Tarun Lalwan链接并根据Joyce Babu帖子,有一个undocumented option来自gitlab runner repos in the
 [runners.docker]部分

network_mode : Add container to a custom network

所以我必须在config.toml中使用我的网络名称设置此选项

[[runners]]
  ...
  [runners.docker]
    ...
    network_mode = "gitlab_default"

或者从命令行创建运行器时

docker exec -it gitlab_gitlab-runner_1 gitlab-runner register \
--non-interactive \
--url http://gitlab_gitlab_1 \
--registration-token _wgMgEx3nBocYQtoi83c \
--executor docker \
--docker-image alpine:latest \
--docker-network-mode gitlab_default
原文链接:/docker/436160.html

猜你在找的Docker相关文章