Have a Jenkins instance with a specific user, say jenkins
, and you decided you needed to use docker commands from within Jenkins.
How does one go about doing that?
There are a couple of steps that need done. Obviously you start by installing docker.
Well it seems that installing Docker on Centos7 via yum
does not create a docker
group — rather, it creates a dockerroot
group.
So one must follow the instructions here to correctly add the jenkins
user to that group.
If one were to try running docker commands within Jenkins after this is done, it will not work. One still ends up with the following error in the Jenkins console
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Interestingly enough running the same on the command prompt works just fine.
Even a Jenkins safeRestart
did not help either.
The issue lies in the fact that our Jenkins instance was being managed as a service. Restarting the service did it!
So there you have it — make sure you are adding the jenkins
user to the right group, and systemctl restart jenkins
afterwards.