Trouble getting docker to run with gitlab-runner

I’ll start off by explaining what i eventually want to accomplish:

  • Have a gitlab-runner instance running inside a docker container that I can share with people working on the same repository.
  • This docker container should have all the dependencies for the project met, and should be able to run our project
  • The goal will eventually be to have a CI/CD Pipeline using a docker container on either my machine or someone else’s. We are all working on forked repos, so it would be most helpful to have the pipeline run in the parent repository, right before a Merge Request is merged.

Describe your question in as much detail as possible:

I began this process by downloading the gitlab/gitlab-runner:latest docker container. Then, I used this Dockerfile and these scripts(Script1- Package Installation, Script2 - Build Script) to get everything set up. Once I mangled my way through apt-get install and everything looked right, I ran the following command on my computer (host machine) and got a docker container that could compile my project:

sudo docker build -f ./Dockerfile . -t gitlab/gitlab-runner:game-build

Once I run this, I get the following as output:

sudo docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
gitlab/gitlab-runner   game-build          d654b3963ee4        2 minutes ago       1.38GB
gitlab/gitlab-runner   latest              a0153b77b0da        20 hours ago        461MB

From the output of the build command, I can verify that the project did in fact build.

Now that I’m confident the project can build inside the container, I moved to trying to run the container gitlab/gitlab-runner:game-build as a pipeline runner.

I attempted to follow this guide (Runner Registration), I ran the following command:

sudo docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner \
 gitlab/gitlab-runner:game-build register

During this process, I ran through the registration process, and successfully see my docker container as a registered runner in my project CI/CD settings. However, as you can see below, in the settings, I have a warning sign (when hovering over, it reads "New Runner, has not connected yet).

22-07-20-at-23:27:55

When I attempt to run the docker container using docker run <options> gitlab/gitlab-runner:game-build, I get the following as output, but then I don’t see any update to the Gitlab CI/CD interaface (it’s running, but I can’ t seem to have it connect)

 sudo docker run gitlab-runner:game-build 
Runtime platform                                    arch=amd64 os=linux pid=456437 revision=353dd94e version=13.2.0
Starting multi-runner from /etc/gitlab-runner/config.toml...  builds=0
Running in system-mode.                            
                                                   
Configuration loaded                                builds=0
listen_address not defined, metrics & debug endpoints disabled  builds=0
[session_server].listen_address not defined, session endpoints disabled  builds=0

What do I need to do to have my docker container connect to the gitlab server? I’m not sure how to go into the docker and see if the config.toml is there, since the container is not interactive.

As a side question, how can I make it so that the docker container spawns a shell? I ask because it has been very difficult to debug docker commands without some way of verifying installation paths interactively through a shell… Is there a way I can make a shell spawn with the gitlab-runner container?

Thanks for taking the time to be thorough in your request, it really helps!

I found something kind of interesting. I had previously set up a runner in my local machine. When I ran

sudo gitlab-runner --debug run 

I found in the output that there is a “runners” section that describes what address the runner is listening to:

Runtime platform                                    arch=amd64 os=linux pid=509388 revision=353dd94e version=13.2.0
Starting multi-runner from /etc/gitlab-runner/config.toml...  builds=0
Checking runtime mode                               GOOS=linux uid=0
Running in system-mode.                            
                                                   
Configuration loaded                                builds=0
listenaddress: ""
sessionserver:
  listenaddress: ""
  advertiseaddress: ""
  sessiontimeout: 1800
concurrent: 1
checkinterval: 0
loglevel: null
logformat: null
user: ""
runners:
- name: semidef's machine
  limit: 0
  outputlimit: 0
  requestconcurrency: 0
  runnercredentials:
    url: https://gitgud.io/
    token: <Secret> 
    tlscafile: ""
/* More text. */
sentrydsn: null
modtime: 2020-07-20T21:36:18.406083984-07:00
loaded: true
  builds=0
Waiting for stop signal                             builds=0
listen_address not defined, metrics & debug endpoints disabled  builds=0
[session_server].listen_address not defined, session endpoints disabled  builds=0
Starting worker                                     builds=0 worker=0
Feeding runners to channel                          builds=0
Dialing: tcp gitgud.io:443 ...                     
Checking for jobs... nothing                        runner=oWQbdZsK

However, when I do the same for my docker container, this is what I get:

sudo docker run gitlab/gitlab-runner:game\
    -build --debug run 
Runtime platform                                    arch=amd64 os=linux pid=6 revision=efa30e33 version=13.2.1
Starting multi-runner from /etc/gitlab-runner/\
    config.toml...  builds=0
Checking runtime mode                               GOOS=linux uid=0
Running in system-mode.                            
                                                   
Configuration loaded                                builds=0
listenaddress: ""
sessionserver:
  listenaddress: ""
  advertiseaddress: ""
  sessiontimeout: 1800
concurrent: 1
checkinterval: 0
loglevel: null
logformat: null
user: ""
runners: []
sentrydsn: null
modtime: 2020-07-22T10:01:18Z
loaded: true
  builds=0
Waiting for stop signal                             builds=0
listen_address not defined, metrics & debug endpoints disabled  builds=0
[session_server].listen_address not defined, session endpoints disabled  builds=0
Feeding runners to channel                          builds=0
Starting worker                                     builds=0 worker=0
Feeding runners to channel                          builds=0

I think I’ve narrowed down the issue to me not having a config.toml file in the docker container. However, I’m confused, since the registration step should have created the config.toml file, right?

I found out how “enter” the docker container and spawn a bash shell using the entrypoint flag in the docker run. From here, I was able to verify the contents of the config.toml of my docker container…

sudo docker run --entrypoint="bash" -it game-build:ubuntu 
root@5ddf8f61b266:/~ ls /etc/gitlab-runner/
certs  config.toml
root@5ddf8f61b266:/~ cat /etc/gitlab-runner/config.toml 
concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800
root@5ddf8f61b266:/~# 

How can I re-configure this?