简体   繁体   中英

ERROR: Job failed (system failure): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? on windows 10

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

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

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

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

在 Docker 桌面上公开端口

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM