LoginSignup
15
13

More than 5 years have passed since last update.

gitlab-ciでCouldn't resolve hostがでるとき

Posted at

Gitlab-ciのDocker executorを使ってビルドをしようとしたとき、gitlabへのアクセス部分で失敗するときの対処法。

環境

  • CentOS7
  • gitlab-ce 8.8.0
  • gitlab-ci 1.2.0

出現するエラー


gitlab-ci-multi-runner 1.2.0 (3a4fcd4)
Using Docker executor with image python:3.5.1 ...
Pulling docker image python:3.5.1 ...

Running on runner-9be17f29-project-46-concurrent-0 via 819cfa8c4195...
Cloning repository...
Cloning into '/builds/********/TESTREPO'...
fatal: unable to access 'http://gitlab-ci-token:xxxxxx@gitlabのホスト名/********/TESTREPO.git/': Couldn't resolve host 'gitlabのホスト名'

ERROR: Build failed: exit code 1

gitlabのレポジトリのアクセスで名前解決ができていない、と。

名前解決できるようにする

公式サイトを確認する。

設定値 説明
extra_hosts specify hosts that should be defined in container environment

変更するファイルは、以下にある。ここのextra_hostsに値を書くことで名前解決ができるようにする。

  • /etc/gitlab-runner/config.toml

変更後は保存して終了。再度、registerはする必要なし。

Example:

[runners.docker]
  host = ""
  hostname = ""
  tls_cert_path = "/Users/ayufan/.boot2docker/certs"
  image = "ruby:2.1"
  privileged = false
  cap_add = ["NET_ADMIN"]
  cap_drop = ["DAC_OVERRIDE"]
  devices = ["/dev/net/tun"]
  disable_cache = false
  wait_for_services_timeout = 30
  cache_dir = ""
  volumes = ["/data", "/home/project/cache"]
  extra_hosts = ["other-host:127.0.0.1"]
  links = ["mysql_container:mysql"]
  services = ["mysql", "redis:2.8", "postgres:9"]
  allowed_images = ["ruby:*", "python:*", "php:*"]
  allowed_services = ["postgres:9.4", "postgres:latest"]

もし、hoge-serverが192.168.0.1で、bar-serverが192.168.0.2あるならば、extra_hostsに次のように設定する。


  extra_hosts = ["hoge-server:192.168.0.1", "bar-server192.168.0.2"]
15
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
13