Run Docker commands in Jenkins Job

Aneesh Kumar
Jun 2, 2015 · 2 min read

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..

Image for post
Image for post

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
Image for post
Image for post

Now Jenkins can run docker commands and Job built successfully.

Image for post
Image for post
Image for post
Image for post

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store