问题
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.
回答1:
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.
回答2:
You can configure the container dns with the --dns
flag to docker run
(https://docs.docker.com/engine/reference/run/#network-settings), but it should use the host dns by default.
回答3:
In case your Gitlab installation also runs as a Docker container, just linking your gitlab-runner to the gitlab container should work:
docker run -d --name gitlab-runner --restart always --link gitlab \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:latest
This way Docker takes care of making the host 'gitlab' available inside gitlab-runner.
来源:https://stackoverflow.com/questions/34185388/how-do-i-get-a-docker-gitlab-ci-runner-to-access-git-on-its-parent-host