I am new to docker. I just tried to use docker in my local machine(Ubuntu 16.04) with Jenkins.
I configured a new job with below pipeline script.
node {
stage('Build') {
docker.image('maven:3.3.3').inside {
sh 'mvn --version'
}
}
}
But it fails with below error.
I`m using the official jenkins docker image (https://hub.docker.com/r/jenkins/jenkins) but I think this solution is applicable to most use cases where we want to run Docker inside a Docker container.
The recommended way for using Docker inside a Docker container, is to use the Docker deamon of the host system. Good article regarding that: https://itnext.io/docker-in-docker-521958d34efd.
The secret to handle the permission issue, which this question is about, is to add permissions for the user of the container inside the container, not the host system. Only root user has permissions to do that by default, so
will do it. Remember to restart the container.
I guess the simpliest way to achive this is to create a customised Dockerfile:
2018-08-19
I have been stuck for days on this one and as I haven't found a complete answer with the why and how, I will post one for other people that stumble on the same problem and answers from above do not work.
These are the 3 crucial steps when running Jenkins inside docker:
/var/run/docker.sock
to the jenkins container in order to be able to use the docker from the host.sudo usermod -a -G docker jenkins
in order to add jenkins to the docker group. However, here you might run into a permission problem if the host docker and the container docker don't have the same group id so it is very important to adjust the container docker's gid to be the same as the host docker gidYou can do this as a part of a launch script or simply by using
exec
and doing it manually:groupmod -g <YOUR_HOST_DOCKER_GID> docker
.Also, do not change permissions of the
/var/run/docker.sock
to 777 or stuff like that because that is a big security risk, you are basically giving everyone permission to use docker on your machineHope this helps
I added the jenkins user to root group and restarted the jenkins and it started working.
I am running Jenkins inside a docker container. The simplest solution for me was to make a custom image that dynamically sets the GID, like:
See: https://github.com/jenkinsci/docker/issues/263
Alternatively you could launch jenkins with the following options:
This assumes your jenkins image has docker client installed. See: https://getintodevops.com/blog/the-simple-way-to-run-docker-in-docker-for-ci
The user
jenkins
needs to be added to the groupdocker
:Then restart Jenkins.
Edit
If you arrive to this question of stack overflow because you receive this message from docker, but you don't use jenkins, most probably the error is the same: your unprivileged user does not belong to the docker group.
You can do:
or whatever your username is.
You can check it at the end doing
cat /etc/group | grep 'docker'
and see something like this:in one of the lines.
As Ilya Kolesnikov says in the comment, re-login!
I have Jenkins running in Docker and connected Jenkins is using Docker socket from host machine Ubuntu 16.04 via volume to /var/run/docker.sock.
For me solution was:
1) Inside Docker container of Jenkins (
docker exec -it jenkins bash
on host machine)2) On host machine:
664
means - read and write(but not execute) for owner and users from group.