Gitlab runner docker Could not resolve host

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 03:32:43

Thanks to Tarun Lalwan link and according to Joyce Babu post, there are an undocumented option from the gitlab runner repos in the [runners.docker] section

network_mode : Add container to a custom network

So I have to set this option with my network name in the config.toml like

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

OR when create the runner from command line

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

In case this helps others looking for this..

Same problem but GitLab and GitLab Runner run on different machines in LAN. DNS is working and ping gitlab works, except inside dockers:

Reproduce problem:

$ sudo docker run -it alpine ping gitlab
ping: bad address 'gitlab'
^C

But works with DNS given:

$ sudo docker run -it --dns=172.168.0.1 alpine ping gitlab
PING gitlab (172.168.0.5): 56 data bytes
64 bytes from 172.168.0.5: seq=0 ttl=63 time=0.536 ms
^C

Config actual LAN DNS for docker.

Edit /etc/docker/daemon.json on the GitLab Runner (file did not exist yet) with contents:

{
    "dns": ["172.168.0.1", "1.1.1.1"]
}

Test again, now OK:

$ sudo docker run -it --dns=172.168.0.1 alpine ping gitlab
PING gitlab (172.168.0.5): 56 data bytes
64 bytes from 172.168.0.5: seq=0 ttl=63 time=0.455 ms
64 bytes from 172.168.0.5: seq=1 ttl=63 time=0.905 ms
^C

If this is not how its supposed to be done, i'd be happy to hear.
If this problem shouldnt aught to exist in the first place, i'd be happy to hear as well. I was surprised to not find much references online to this problem for GitLab Runner..

As I can see you have defined a network already which means that both gitlab and gitlab-runner are in the same network. you can verify that by using docker inspect. so you need to remove links as you don't need it.

In order to set a network alias you need to change the network part at gitlab service to the following:

gitlab:
  ...
  networks:
    default:
      aliases:
        - gitlab.localhost.com

References:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!