1

introduction: I'm trying to build an Angular app on the slave, In order not to install nodejs on the slave I use docker on the slave to build and cleanup.

The problem

run docker commands directly on the slave with the Jenkins user works well

jenkins@ubuntu_server:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
...

When the jenkinsfile try to run docker commands on the slave it fails with permission denied error.

+ docker inspect -f . node:current-alpine3.10

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.40/containers/node:current-alpine3.10/json: dial unix /var/run/docker.sock: connect: permission denied

here relevant jenkinsfile part "ubuntu_server" is a label of the slave

pipeline {
    agent {
        docker {
                image 'node:current-alpine3.10'
                label 'ubuntu_server'
                args  '-v /tmp:/tmp'
                }
    }
m_g
  • 61
  • 1
  • 6
  • 1
    Have you restarted Jenkins after you added the user `jenkins` to the group `docker`? – β.εηοιτ.βε Jun 03 '20 at 19:42
  • Also, have you logged out and back in? – β.εηοιτ.βε Jun 03 '20 at 19:42
  • 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) – β.εηοιτ.βε Jun 03 '20 at 19:42
  • @β.εηοιτ.βε the answar in the link doesn't relevant for me cause I can run commands on the slave.what – m_g Jun 03 '20 at 19:49
  • @β.εηοιτ.βε You right after restart Jenkins everything works well, thanks a lot – m_g Jun 03 '20 at 20:04

1 Answers1

0

I had the problem as well after adding a new slave node on a remote server.I did what most others suggested, adding to the docker group. I was able to execute docker commands with the user no problem when I SSHed in but I was still getting the error when building with Jenkins.

Turns out Jenkins never closed its connection to the server for the node which I had configured before adding that user to the docker group.

In the end the resolution for me was to go into Jenkins > Manage Jenkins > Manage Nodes and Clouds > {My Node} and disconnect the node. Upon reconnecting it worked fine.

James Taylor
  • 261
  • 1
  • 5