Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a Docker Gitlab CI runner to access Git on its parent host?

Tags:

docker

gitlab

Gitlab is setup on our internal network at http://gitlab

Docker containers on the same machine can't connect to it.

How do I configure docker so that it knows gitlab is its parent?


The problem exhibits itself when Gitlab CI attempts to run a build (inside a Docker container):

Cloning into '/builds/ns/project'... fatal: unable to access 'http://gitlab-ci-token:xxxxxx@gitlab/ns/project.git/': Couldn't resolve host 'gitlab'

I've tried adding the network's DNS servers to DOCKER_OPTS in /etc/default/docker to no avail.

like image 744
bcmcfc Avatar asked Dec 09 '15 17:12

bcmcfc


1 Answers

According to the GitLab CI Runner Advanced configuration, you can try to play with the extra_hosts param in your GitLab CI runner. In /etc/gitlab-runner/config.toml :

[[runners]]
  url = "http://gitlab/ci"
  token = "TOKEN"
  name = "my_runner"
  executor = "docker"
  [runners.docker]
    host = "tcp://<DOCKER_DAEMON_IP>:2375"
    image = "..."
    ...
    extra_hosts = ["gitlab:192.168.0.39"]

With this example, when inside the container running the test git will try to clone from gitlab, it will use the 192.168.0.39 as IP for this hostname.

like image 193
PierreF Avatar answered Oct 11 '22 21:10

PierreF