How to solve Docker permission error when trigger by Jenkins

In your VPS server terminal, do this to add your jenkins user to the docker group:

sudo usermod -aG docker jenkins

Then restart your jenkins server to refresh the group.

Take into account any security issue that this could produce:

Warning: The docker group grants privileges equivalent to the root user. For details on how this impacts security in your system, see Docker Daemon Attack Surface.

Refer to the docs


Edit (mentioned by @iger): Just make sure to restart the Jenkins from command-line (i.e. sudo service jenkins restart), but not through the rest endpoint (http:///restart)


Running

sudo usermod -aG docker jenkins

and then

sudo service jenkins restart

worked perfectly for me.


  1. Add user to docker group as it described here.
  2. Start jenkins with this command: docker run -d -u root --restart on-failure -p "8080:8080" -p "50000:50000" -v $PWD/jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean

root user required because without it you will not be able to execute root task, example: apk update && apk install ...

Tags:

Docker

Jenkins