4

Trying to transform a project in gitlab to docker image. The gitlab is selfhosted. This is the error I get:

Running with gitlab-runner 13.12.0 (7a6612da)
on test -KnwQXuT
Preparing the "docker" executor
ERROR: Failed to remove network for build
ERROR: Preparation failed: Got permission denied while trying to connect to the Docker daemon 
socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.25/info: dial 
unix /var/run/docker.sock: connect: permission denied (docker.go:858:0s)

I added a runner,registered it, created a gitlab-ci.yml with docker template which I left unmodified. As solutions I tried chmod 666 /var/run/docker.sock before and after adding the runner but it did not work. I also added sudo before running and registering the docker runner but still no success. I found another option to add my docker user to group docker but all my users are in the docker group. The docker runner is run as a docker image. I did not know what to do...Please help. I`m am trying for about 10 days with no success... Thanks in advance

SerCio
  • 105
  • 3
  • 8
  • can you provide you runner config – antoniomerlin Jun 22 '21 at 11:49
  • 1. docker volume create gitlab-runner-config 2.docker run -d --name gitlab-runner --restart always \ -v /var/run/docker.sock:/var/run/docker.sock \ -v gitlab-runner-config:/etc/gitlab-runner \ gitlab/gitlab-runner:latest 3. docker run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner:latest register – SerCio Jun 22 '21 at 11:59
  • These are the 3 steps that i took – SerCio Jun 22 '21 at 12:06
  • Does this answer your question? [Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock](https://stackoverflow.com/questions/47854463/docker-got-permission-denied-while-trying-to-connect-to-the-docker-daemon-socke) – Ulrich Eckhardt Jan 26 '22 at 07:49

2 Answers2

13
  1. Create docker group if not exist : sudo groupadd docker
  2. Add user to docker group : sudo usermod -aG docker ${USER}
  3. Change docker.sock to new permission : sudo chmod 666 /var/run/docker.sock
  4. Finally restart docker daemon service : sudo systemctl restart docker
Javad
  • 373
  • 4
  • 20
3

When you use gitlab self-hosted runner, by default, it creates a user named gitlab-runner. You need to assign the permissions to it.

sudo usermod -aG docker gitlab-runner

this will assign the correct permissions to the gitlab-runner and should pull the docker images on that VM.