Search code examples
dockergitlab-ci-runnercicd

Gitlab-runner in docker with ci/cd dind error


I have gitlab-runner running inside the docker on my server. This gitlab-runner is successfully registered for my gitlab. But when I run ci/cd I get an error:

ERROR: Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?

error here

my ci file task

my config.toml file for gitlab-runner

Please tell me how to fix this error.

I've already recreated gitlab-runner and redid the ci file several times. Nothing worked. I created gitlab-runner with the command -

docker run -d --name gitlab-runner --restart always -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest

Then going into the docker itself I ran the command -

gitlab-runner register --url https://gitlab.com --token <my_token>

In CI/CD Pipeline log

Preparing the "docker" executor
00:17
Using Docker executor with image docker:git ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image sha256:881c987bf80d40ddcc0f01d845242611380eba9115d9eeab12713c5215c21959 for docker:dind with digest docker@sha256:5edfe3067bdd8b76818b036d8ef61846696af4d458ba527356c5484fcd692c2a ...
Waiting for services to be up and running (timeout 30 seconds)...
Pulling docker image docker:git ...
Using docker image sha256:fce9ca002cbb40452df4ab64ec9b726fd1ba7fbc2eb3b4b482da87f6013541b5 for docker:git with digest docker@sha256:e86452c5f015fafa3957fa4cf7a38ac4b091a317fc0481f00f36dae6d8b065af ...
Preparing environment
00:02
Running on <runner_info> via 428a77e8bbfe...
Getting source from Git repository
00:06
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /builds/<road>/.git/
Checking out a64f955b as detached HEAD (ref is develop)...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:04
Using docker image sha256:fce9ca002cbb40452df4ab64ec9b726fd1ba7fbc2eb3b4b482da87f6013541b5 for docker:git with digest docker@sha256:e86452c5f015fafa3957fa4cf7a38ac4b091a317fc0481f00f36dae6d8b065af ...
$ echo "running publish state"
running publish state
$ docker build -t $TAG_LATEST .
ERROR: Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?

Solution

  • When you do docker run to start your runner, you also need to pass the --privileged flag.

    docker run --privileged ...
    

    You may also need to set the variables DOCKER_HOST and DOCKER_TLS_CERTDIR in your job.

    myjob:
      # ...
      variables:
        DOCKER_HOST: "tcp://docker:2375"
        DOCKER_TLS_CERTDIR: ""