How to use docker from Jenkins internal docker container

I ran into the following problem: I created a Jenkins docker container and connected the docker socket on the host to the container. Like this:

docker run -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 -p 50000:50000 -d --name jenkins --restart unless-stopped jenkins

Then, when I try to create some jobs on jenkins, I get the usual "denied" message:

Granted permission to refuse when trying to connect to the Docker socket daemon in unix: ///var/run/docker.sock: Get http: //%2Fvar%2Frun%2Fdocker.sock/v1.29/images/json : type unix / var / run / docker.sock: connect: permission denied

But this problem does not occur if I attach to the container and run the command using the root user.

How can i fix this?

I cannot add the jenkins user to the docker group on the host by running sudo gpasswd -a jenkins docker(because the host does not have the jenkins user, only in the container), and I also can not run this command inside the container (because the container does not know about any docker group) . Any tips on how to solve this?

+4
source share
1 answer

You can add a docker group to the container. Do it in bash:

groupadd -g <docker-group-id> docker

Find out how it <docker-group-id>runs on the host:

ls -ln /var/run/docker.sock

Then add user jenkins to the docker group:

gpasswd -a jenkins docker

Consider any security issue that may arise:

. , root. , , . Docker Daemon Attack Surface.

docs

+2

Source: https://habr.com/ru/post/1682802/


All Articles