天天看點

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