Sunday, December 2, 2018

When we get access denied error with docker using jenkins

This is not specific to docker, but any app.

We cannot access jenkins generally with sudo commands as it launches a separate terminal tty session.Which cannot be done using jenkins directly.

So, we need to add the OS user we are using with jenkins to sudoers as giving access to this single app or complete list.If you want, you check how to change the user in our separate post.

I added my user to have access to all the apps.

The sudoers file /etc/sudoers, not recommended to edit directly, use below command.

sudo visudo

Then, enter below entries.


# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL #this line is already available.
%adm ALL=(ALL) ALL #not necessary, but added as my user belongs to adm and docker groups.
%docker ALL=(ALL) ALL


Reference 1 2 3 4 5 6

Without sudo I am able to access docker but with below command, I am getting error for access.
docker run -t -d -u 1000:1000 -w /var/lib/jenkins/workspace/test -v /var/lib/jenkins/workspace/test:/var/lib/jenkins/workspace/test:rw,z -v /var/lib/jenkins/workspace/test@tmp:/var/lib/jenkins/workspace/test@tmp:rw,z maven:3-alpine cat
docker: Error response from daemon: error while creating mount source path '/var/lib/jenkins/workspace/test': mkdir /var/lib/jenkins: permission denied.
When I check the permissions,they already exists.
uday@jenkins-server:~$ ls -l /var/lib/jenkins/workspace
total 8
drwxr-xr-x 2 uday uday 4096 Nov 15 06:51 test
drwxr-xr-x 2 uday uday 4096 Nov 15 07:32 test@tmp
When I checked dockerd, the path not found, so installed docker.io
sudo apt install docker.io
Then the issue is not replicating now.
I installed docker earlier with docker snap command.









No comments:

Post a Comment