Reputation: 12023
I am using the gitlab/gitlab-ce:latest docker image on a Mac to build some custom gitlab runner that will span a custom maven image. At the moment I am having an issue to setup the basic environment using docker compose
See my docker-compose.yml below.
version: '3.7'
services:
gitlab:
image: 'gitlab/gitlab-ce:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
# external_url 'https://gitlab.example.com'
# Add any other gitlab.rb configuration here, each on its own line
ports:
- '8080:80'
- '8443:443'
- '2022:22'
volumes:
- '${HOME}/gitlab/config:/etc/gitlab'
- '${HOME}/gitlab/logs:/var/log/gitlab'
- '${HOME}/gitlab/data:/var/opt/gitlab'
networks:
default:
aliases:
- 'gitlab.example.com'
gitlab-runner:
image: 'gitlab/gitlab-runner:latest'
hostname: 'runner.example.com'
restart: always
volumes:
- '${HOME}/gitlab-runner/config:/etc/gitlab-runner'
- '/var/run/docker.sock:/var/run/docker.sock'
depends_on:
- gitlab
networks:
default:
aliases:
- 'runner.example.com'
At the moment I can successfully register the runner in the gitlab server and make a merge request
To register the runner I use the command below from within a running docker gitlab-runner container.
#[host] docker exec -it <gitlab-runner container-id> bash
#[gitlab-runner] gitlab-runner register \
--non-interactive \
--url http://gitlab.example.com \
--registration-token "xxxxxx" \
--description "docker-maven-runner" \
--tag-list "docker" \
--run-untagged="true" \
--executor "docker"\
--docker-image "maven:latest"
But the pipeline always fails with the following error
Running with gitlab-runner 12.10.2 (c5874a4b)
on docker-maven-runner 7zhsdXRx
Preparing the "docker" executor
00:02
Using Docker executor with image maven:latest ...
Pulling docker image maven:latest ...
Using docker image sha256:44e27997f4c0493779146fc89ab571f5f829ac6538d0d7d40cbe9fe2b36d4a60 for maven:latest ...
Preparing environment
00:02
Running on runner-7zhsdxrx-project-2-concurrent-0 via runner.example.com...
Getting source from Git repository
00:01
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/hramanmcg/sonar-java-test/.git/
fatal: unable to access 'http://gitlab.example.com/hramanmcg/sonar-java-test.git/': Failed to connect to gitlab.example.com port 80: Connection refused
Uploading artifacts for failed job
00:02
ERROR: Job failed: exit code 1
My guess is that I need some way to specify the network so when the runner span out the container it will be connected to the correct network, but I can't find how to do this
Some debug info
#docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------------------------------------------------------------------------
sonar-assistant-docker_gitlab-runner_1 /usr/bin/dumb-init /entryp ... Up
sonar-assistant-docker_gitlab_1 /assets/wrapper Up (healthy) 0.0.0.0:2022->22/tcp, 0.0.0.0:8443->443/tcp, 0.0.0.0:8080->80/tcp
#docker network ls
NETWORK ID NAME DRIVER SCOPE
2fb969181eb3 bridge bridge local
0f73fd4baa79 host host local
96216f1d093e none null local
7b120474fd1b sonar-assistant-docker_default bridge local
Upvotes: 1
Views: 927
Reputation: 12023
Answering my own question.
I found an option on the registration that set the docker network.
using --docker-network-mode
.
I am not sure how to use it in interactive mode but in none interactive the following worked for me
#[host] docker exec -it <gitlab-runner container-id> bash
#[gitlab-runner] gitlab-runner unregister --all-runners
#[gitlab-runner] gitlab-runner register \
--non-interactive \
--url http://gitlab.example.com \
--registration-token "xxxx" \
--description "docker-maven-runner" \
--executor "docker" \
--docker-image "maven:latest" \
--docker-network-mode sonar-assistant-docker_default
Using GitLab Community Edition 12.10.2 and Gitlab Runner 12.10.2 and Docker desktop 2.3.0
Upvotes: 3