Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Jenkins run docker without sudo

Tags:

docker

jenkins

I would like to run Docker shell commands on Jenkins like:

docker ps

Is it possible to do it with out using any plugins? Since Jenkins isn't a user, but a service account how can I add to docker group?

like image 463
Rudziankoŭ Avatar asked Sep 22 '16 12:09

Rudziankoŭ


People also ask

Can Docker run without Sudo?

The Docker daemon always runs as the root user. If you don't want to preface the docker command with sudo , create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.

Can I install Docker without root?

Rootless mode allows running the Docker daemon and containers as a non-root user to mitigate potential vulnerabilities in the daemon and the container runtime. Rootless mode does not require root privileges even during the installation of the Docker daemon, as long as the prerequisites are met.


2 Answers

First execute

sudo groupadd docker

Then execute

sudo usermod -aG docker $USER

Then logout its important to logout because your group membership is re-evaluated

Login and try again

docker ps

It works!

like image 137
Javier Rodriguez Avatar answered Oct 19 '22 02:10

Javier Rodriguez


I had the issue when I was running from jenkins pipeline. I added jenkins user to docker group, restarted the docker engine and rebooted the machine as well. However I still get the same error dial unix /var/run/docker.sock: connect: permission denied.

Finally I added jenkins to root group and it resolved my issue (ubuntu 18.04) (VM on Azure)

sudo gpasswd -a jenkins root
sudo service docker restart
like image 37
Sudhakar MNSR Avatar answered Oct 19 '22 03:10

Sudhakar MNSR