I did not resolve my problem but I know why it does not work. If you are using docker executor, when you launch a job, gitlab-runner binary will start a special container. This container is gitlab-runner-helper and will manage git, caches, etc.
The container is started by calling the Docker Engine API running on the host (localhost, the physical machine). But, since it's started "manually", it is not linked to any bridge network. Or, at least not linked to the docker-compose network. So, the helper does not even know that that the gitlab container exists.
I just want to have gitlab and gitlab-runner (using docker executor) working on my localhost. I want to install and manage them with docker and docker-compose.
gitlab: container_name: my-container-gitlab image: gitlab/gitlab-ce:latest ports: - "443:443" - "9090:80" - "22:22" environment: GITLAB_OMNIBUS_CONFIG: | external_url 'http://gitlab' volumes: - ./gitlab/config:/etc/gitlab - ./gitlab/logs:/var/log/gitlab - ./gitlab/data:/var/opt/gitlab gitlab-runner: container_name: my-container-gitlab-runner image: gitlab/gitlab-runner:latest volumes: - ./gitlab-runner/config:/etc/gitlab-runner - /var/run/docker.sock:/var/run/docker.sock
Gitlab works like a charm.
Runner registration works also :
docker-compose run gitlab-runner register -n \ --url http://gitlab/ \ --registration-token xxxxxxxxxx \ --executor docker \ --docker-image alpine \ --description "My Docker Runner"
But when launching a job from Gitlab web UI, I get this :
Running with gitlab-runner 11.11.2 (ac2a293c) on My Docker Runner sBqMfFys Using Docker executor with image alpine ... Pulling docker image alpine ... Using docker image sha256:055936d3920576da37aa9bc460d70c5f212028bda1c08c0879aedf03d7a66ea1 for alpine ... Running on runner-sBqMfFys-project-1-concurrent-0 via 881cd3e0423c... Initialized empty Git repository in /builds/root/bertrand-malvaux/.git/ Fetching changes... Created fresh repository. fatal: unable to access 'http://gitlab-ci-token:[MASKED]@gitlab/root/bertrand-malvaux.git/': Could not resolve host: gitlab ERROR: Job failed: exit code 1
For what I investigated so far :
- gitlab-runner image is built with Ubuntu 16.04
- it embeds git
- and uses dumb-init to manage processes
- when container starts, it launches dumb-init (entrypoint)
- dumb-init launches gitlab-runner binary (written in Go)
- this binary will launch git (git clone, git fetch, etc.). See https://gitlab.com/gitlab-org/gitlab-runner/blob/master/shells/abstract.go
But, as you can see in the above error, the binary does not "see" the gitlab hostname. I modified the image to check if it can see the gitlab container outside the binary only with dumb-init, and the answer is yes.
Do you have any idea how to make this works ?