Preparation failed: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
Asked Answered
T

3

7

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

Thalia answered 22/6, 2021 at 9:39 Comment(4)
can you provide you runner configPresbyter
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 registerThalia
These are the 3 steps that i tookThalia
Does this answer your question? Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sockGignac
A
17
  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
Anew answered 22/6, 2021 at 12:12 Comment(4)
What user ? I am root on linuxThalia
@Thalia If you root user not required any access for dockerAnew
It doesn`t work. I have given the command sudo chmod 777 /var/run/docker.sock and still receiving error. I do not know what to do...Thalia
Please don't give advice of chmod 666 the docker.sock as this has huge security implications as this allows any user to become rootInflammatory
C
10

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.

Caro answered 26/1, 2022 at 7:38 Comment(0)
S
0

Worked as a charm! Thanks!

sudo usermod -aG docker gitlab-runner Makes sense as the gitlab-runner user is created when you register the shell executor.

Solnit answered 22/5 at 6:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.