I have a dockerized GitLab and GitLab Runner installation, with following docker-compose.yml:
version: "3"
services:
gitlab:
image: gitlab/gitlab-ee:latest
container_name: gitlab
restart: always
hostname: gitlab
ports:
- "45022:22"
- "45080:80"
- "45443:443"
volumes:
- /srv/gitlab/config:/etc/gitlab
- /srv/gitlab/logs:/var/log/gitlab
- /srv/gitlab/data:/var/opt/gitlab
python-runner:
image: gitlab/gitlab-runner:latest
container_name: python-runner
hostname: python-runner
volumes:
- /srv/python-runner/config:/etc/gitlab-runner
- /var/run/docker.sock:/var/run/docker.sock
environment:
- CI_SERVER_URL=http://gitlab/ci
- RUNNER_TOKEN=myTokenCode
- RUNNER_DESCRIPTION=Python 2.7.14
- RUNNER_EXECUTOR=docker
- DOCKER_IMAGE=python:2.7.14
restart: always
I have registered the runner:
docker exec -it python-runner gitlab-runner register \
--non-interactive \
--url "http://gitlab/" \
--registration-token "${GITLAB_REGISTRATION_TOKEN}" \
--description "Python 2.7.14" \
--executor "docker" \
--docker-image python:2.7.14
The runner is listed in the Runners list:
I can ping the gitlab host from the python-runner:
» docker exec -it python-runner bash
root@python-runner:/# ping gitlab
PING gitlab (172.20.0.2) 56(84) bytes of data.
64 bytes from gitlab.gitlab_default (172.20.0.2): icmp_seq=1 ttl=64 time=0.112 ms
64 bytes from gitlab.gitlab_default (172.20.0.2): icmp_seq=2 ttl=64 time=0.055 ms
^C
--- gitlab ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.055/0.083/0.112/0.029 ms
But when running the pipeline, it fails:
`fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab/group/project.git/': Could not resolve host: gitlab
How is this possible? How can this be solved?
EDIT
It seems the architecture that I am creating is the following:
- gitlab running in
gitlabdocker container - gitlab runner running in
python-runnerdocker container - docker-compose creates a private network
gitlab_default(gitlabis the name of the project), and both thegitlabandpython-runnercontainers can reach it other, by IP and by name. - the
python-runneruses thedockerexecutor to spawn containers during CI (in the host?), based onpython:2.7.14as defined. I do not know how gitlab names these containers, let's call itci-job - the project is cloned in this
ci-jobcontainer, by issuing agit clone. This fails because theci-jobcontainer can not reach thegitlabcontainer, since it is probably in a different network (defaultnetwork?)
I have tried to force the python-runner to spawn containers in the same gitlab_default network, by using --docker-network-mode gitlab_default flag as follows:
docker exec -it python-runner gitlab-runner register \
--non-interactive \
--tag-list python-2.7.14 \
--url "http://gitlab" \
--registration-token "$(GITLAB_REGISTRATION_TOKEN)" \
--name "Python 2.7.14" \
--executor "docker" \
--docker-image python:2.7.14 \
--docker-network-mode gitlab_default
But it still does not work. I am not sure if that's the right flag, since it is poorly documented.
Two questions:
- How can I see the containers that the executor is creating when running CI? Can I enter them and do some debugging there?
- What is the relevant parameter to ensure that the containers spawned by the docker executor are in the same network as the
gitlabcontainer?
EDIT2
After some idle time, my jobs started working. It seems configuring --docker-network-mode did indeed work as expected.

http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab:group/project.git/(note the semi-colon instead of slash)http://gitlab/group/project.gitgit clonecommand does not happen in the runner itself, but in the executor, which is itself a docker container (running in the host I assume, although I see no traces of it when doingdocker ps -a)