Gitlab runner docker Could not resolve host

后端 未结 4 659
半阙折子戏
半阙折子戏 2021-01-04 17:32

Im using 2 containers on my Ubuntu OS: Gitlab-ce and gitlab-runner

Containers names are: gitlab_gitlab_1 and gitlab_gitlab-runner_1

I

相关标签:
4条回答
  • 2021-01-04 18:15

    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:

    • Compose file version 3 reference
    0 讨论(0)
  • 2021-01-04 18:17

    I know this thread is old, but I saw everywhere threads pointing to this one, but did'nt solve for me.

    I got the same error message :

    fatal: unable to access 'http://gitlab.maison.fr:82/angular/test1.git/': Could not resolve host: gitlab.maison.fr

    Adding network_mode = "host" to config.toml solve the problem.

    My config.toml below on my local private network :

    concurrent = 1
    check_interval = 0
    
    [session_server]
      session_timeout = 1800
    
    [[runners]]
      name = "mars"
      url = "http://gitlab.maison.fr:82/"
      token = "TCfHAheTUdWMU2-fFNxK"
      executor = "docker"
      [runners.custom_build_dir]
      [runners.cache]
        [runners.cache.s3]
        [runners.cache.gcs]
        [runners.cache.azure]
      [runners.docker]
        tls_verify = false
        image = "gitlab/gitlab-runner:latest"
        privileged = false
        disable_entrypoint_overwrite = false
        oom_kill_disable = false
        disable_cache = false
        volumes = ["/cache"]
        shm_size = 0
        network_mode = "host"
    
    0 讨论(0)
  • 2021-01-04 18:32

    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..

    0 讨论(0)
  • 2021-01-04 18:35

    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
    
    0 讨论(0)
提交回复
热议问题