Gitlabrunnerdocker无法解析主机

我在Ubuntu操作系统上使用了2个容器:Gitlab-ce和gitlab-runner

容器名称是:gitlab_gitlab_1gitlab_gitlab-runner_1

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

我使用以下命令成功注册了跑步者:

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。我认为问题来自无法解决主机的高山图像。

我该如何解决?

谢谢

docker-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'

docker-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的帖子,gitlab运行器回购中

有一个未记录的选项[runners.docker] section

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

以上是 Gitlabrunnerdocker无法解析主机 的全部内容, 来源链接: utcz.com/qa/404234.html

回到顶部