天天看点

Gitlab CI Could not resolve host: xxxx

Gitlab CI Could not resolve host: xxxx

Gitlab CI构建项目都很正常也很好用,最近却发现构建项目异常,查看控制台发无法拉取git代码,报错信息:

fatal: unable to access 'http://xxx.xxx.xxx.xxx:1024/***************.git/': Could not resolve host: xxx.xxx.xxx.xxx
           

截图如下:

Gitlab CI Could not resolve host: xxxx

一开始以为是不是DNS的问题,把配置改成IP地址也不行,出现 :

Failed to connect to xxx.xxx.xxx.xxx port 1024: Host is unreachable
           

后面查了很多资料没有找到直接的解决办法,只能先放放想办法。。。

经过停下来一天好好思考,应该是docker网络的问题,解决办法如下:

  • 查看docker的网络
[email protected]:~$ sudo docker network list
NETWORK ID     NAME            DRIVER    SCOPE
c752268f795d   bridge          bridge    local
794b39550bcf   harbor_harbor   bridge    local
835566ae7ec1   host            host      local
dd262175f497   none            null      local
           
  • 在gitlab-runner的配置中加入docker网络,在/etc/gitlab-runner/config.toml,增加 network_mode = “host” 即可,如下:
[[runners]]
  name = "hncs-ubuntu-gitlab"
  url = "http://xxx.xxx.xxx.xxx:1024/"
  token = "************"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "ubuntu"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/certs/client", "/cache", "/var/run/docker.sock:/var/run/docker.sock", "/etc/hosts:/etc/hosts"]
    shm_size = 0
    network_mode = "host"  
           
  • 重启gitlab-runner。
sudo gitlab-runner restart