I was trying to setup a docker build job in jenkins using docker-build-publish-plugin. But the problem was jenkins user didn’t have permission to run Docker commands. Initally i tried adding jenkins user to ‘docker’ group but it didn’t work. It keeps throwing an error.
The real problem here is jenkins user doesn't have permission to access the unix socket file of docker process
$ ls -l /var/run/docker.sock
srw-rw — — 1 root docker 0 Apr 23 10:12 /var/run/docker.sock
An easy fix will be change the permission of the file to something 777 or so. But that will open the door for all users in the system, we don’t want that. we want to give access for only one user ie Jenkins user.
Another quick and safe option will be use `setfacl` command to set permission specific to jenkins user.
$ sudo setfacl -m u:jenkins:rw /var/run/docker.sock
Now Jenkins can run docker commands and Job built successfully.