2

I'm trying to set up gitlab CI on a windows 10 PC.

I have created a docker container for gitlab (volumes are docker volumes)

docker run --detach --name gitlab --hostname gitlab.mod --publish 4443:443 --publish 4480:80 --publish 8222:22 --volume gitlab-conf:/etc/gitlab --volume gitlab-logs:/var/log/gitlab --volume gitlab-data:/var/opt/gitlab gitlab/gitlab-ce

Another for the runner

docker run -d --name gitlab-runner -v gitlab-runner-conf:/etc/gitlab-runner gitlab/gitlab-runner:latest

registered

docker run --rm -t -i -v gitlab-runner-conf:/etc/gitlab-runner gitlab/gitlab-runner register --url "http://11.22.33.44:4480/" --registration-token "sEcrEttOkEnfOrgItlAb" --description "Runner" --executor "docker" --docker-image alpine:latest --docker-services postgres:latest

where 11.22.33.44 is the IP of my computer

But when I push my commits, i have an error

Running with gitlab-runner 12.5.0
  on Runner
ERROR: Job failed (system failure): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (executor_docker.go:980:0s)

If I set parameters to expose docker on port 2375 :

  settings > General > Expose daemon on tcp://localhost:2375

And in /etc/gitlab-runner/config.toml in the runner container :

  [runners.docker]
      host = "tcp://11.22.33.44:2375"

I have nearly the same error message :

Running with gitlab-runner 12.5.0 (577f813d)
  on Runner
ERROR: Job failed (system failure): Cannot connect to the Docker daemon at tcp://11.22.33.44:2375. Is the docker daemon running? (executor_docker.go:980:1s)

I don't understand from where this comes from. I have tried some solutions found on internet but till now, nothing worked.

Where can i find some log file to see what happens ? I've looked in the gitlab container /var/log/gitlab log files but I can't find any about details between the 2 containers.

Is there problems between the gitlab hostname, the "localhost" name, the computer IP ? A firewall somewhere ? Is this a problem similar to all those i've seen around ? Does the runner gets the jobs he has to execute but gitlab doesn't hear the answer ?

Most of things i tried so far made the situation getting worst and i would need some hint

My .gitlab-ci.yml (very simple) :

variables:
    HELLO: World

test:
    script:
        - echo $HELLO

My config

Docker Desktop Community edition 2.0.0.3 (Engine 18.09.2)
GitLab Community Edition 12.5.2
Gitlab Runner 12.5.0
Windows 10.0.17763

Thanks

Jice
  • 191
  • 4
  • 16
  • host = "tcp://docker.for.win.localhost:2375" could be modified to host="tcp://11.22.33.44:2375". In case this does not work try setting up ssh. Please refer here for more details https://stackoverflow.com/questions/52432362/how-do-i-connect-to-a-remote-docker-daemon-without-being-root/59371813#59371813 – Shubhanshu Rastogi Dec 20 '19 at 10:23
  • From description it looks like you are trying to create docker runner from docker instance. Shouldn't you start shell runner if your executor is running inside docker? Otherwise your job will try to run docker inside of docker. – makozaki Dec 20 '19 at 11:56
  • No, My 2 docker instances are different ones and the 2 run commands are executed on the host (windows here) – Jice Dec 20 '19 at 12:21
  • @ShubhanshuRastogi : i'm trying your solutions but till now, i can't make them work. The first make me think of one thing : how the gitlab container knows the gitlab-runner's ip and how can i test this ip is not blocked somewhere because I can see in gitlab that the runner is known with a 172.17.0.1 ip and during my experiments, i had a gateway problem with this kind of adress (i don't remember very clearly what happened).. About the ssh hint, exporting the DOCKER_HOST variable isn't enough. There must be something else to do (ssh config between gitlab and the runner ?). I have to explore. Tx – Jice Dec 20 '19 at 14:00

3 Answers3

0

If your goal is to register a docker executor, one simple way is to run a command gitlab-runner.exe register and follow interactive instructions, it will fill up your config.toml

This error also appears when you try to use docker in docker image as you runner image to execute docker commands.

In that case a used runner tag, must have a privileged set to true and in your gitlab-ci file you may define a variable DOCKER_DRIVER: overlay or DOCKER_DRIVER: overlay2

  • Thanks. This may finish with a try to run directly gitlab-runner.exe on the host but I'd prefer to use the docker gitlab-runner image. – Jice Dec 23 '19 at 07:43
  • You mention Docker in docker (like makozaki). Is this something that necesseraly happends when one use a docker gitlab-runner image (like this : https://docs.gitlab.com/runner/install/docker.html). I updated the question to put the very simple .gitlab-ci.yml i try to use. I don't see any "docker in docker" behaviour in this. In this case, what do you mean with "used runner tag, must have privileged set to true" ? – Jice Dec 23 '19 at 07:50
  • Okay, i see what you try to do.. your gitlab-runner itself is a container...after running it, it is known by gitlab with a ip 172.xx.xx.xx and you will get a gateway issue with this ip. The solution is to use your server IP as your container IP. Put this option **--net=host** in your docker run command So it will be known to the gitlab by the server ip – network_newbie Dec 23 '19 at 14:01
  • Yes, that's exactly the point. But i can't make your option work : There is 2 run commands for the runner. One to create and one to register. I tried your option in both commands and in both case, if I put "--net=host" in the run part options, nothing change (the runner IP stays 172...), If i put it in the register part of the 2d command, i have an error (--net not known in this part) and if i put "--net=http://11.22.33.44", I have an error "docker: Error response from daemon: network http://11.22.33.44 not found". (11.22.33.44 is my IP). If I put the 2375 port, it is the same. – Jice Dec 24 '19 at 08:16
  • From forums i've read, it seems that --net=host is only for linux host. Mine is windows. I'm now trying this https://stackoverflow.com/questions/40746453/how-to-connect-to-docker-host-from-container-on-windows-10-docker-for-windows – Jice Dec 24 '19 at 08:53
0

This seems to be solved by

Configuring the runner (/etc/gitlab-runner/config.toml) :

[[runners]]
  [runners.docker]
    host = "tcp://docker.for.win.localhost"
...

or

[[runners]]
  [runners.docker]
    host = "tcp://10.0.75.1"
...

I say seems because I still have errors (but not the same) => ERROR: Preparation failed: Error response from daemon: The requested URL /v1.25/info was not found on this server

Jice
  • 191
  • 4
  • 16
0

There are some extra steps involved when using the runner from within Docker for Windows.


Let's say we have the host (the IP of the machine running Docker) and the GitLab instance defined as below:

HOST: 11.22.33.44

GITLAB_IP: 55.66.77.88

1. Launch the runner, specify and forward the address to reach the host Docker daemon

docker run -p 2375:2375 -d --name gitlab.runner --env DOCKER_HOST=tcp://11.22.33.44:2375 --restart always -v C:/temp/srv/gitlab-runner/config/:/etc/gitlab.runner -v C:/temp/var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest

2. Register the runner with privileged

docker exec gitlab.runner gitlab-runner register -n --url=http://55.66.77.88:9000/ --registration-token=sEcrEttOkEnfOrgItlAb --description="Shared Docker Runner" --executor=docker --docker-image=docker --docker-privileged=true

3. Expose the port Open Settings from Docker Desktop for Windows

Expose port on Docker Desktop

4. Make the port available to the runner

On Docker for windows, the port 2375 is only accessible via the host loopback (For instance http://127.0.0.1:2375 would work but not http://someRemoteAddress:2375). The GitLab Runner is being run inside its container, so we need to redirect whatever comes from the port 2375 on the GitLab runner instance to the Docker instance.

In an elevated Powershell session do:

netsh interface portproxy add v4tov4 listenport=2375 listenaddress=11.22.33.44 connectport=2375 connectaddress=127.0.0.1

Note that these steps are only needed because the runner is running inside a container. If it were running directly on the host, it would have access to the Docker Daemon.