My goal today is used this image with jenkins and modified it with following way.
This image using user jenkins inside container like default. I want run docker inside this container like this user and connect docker in docker in the same host.
Docker CLI (represent in command docker) is connected to a server called Docker Engine via a socket, that is: a file on the filesystem. If you mount this file as a volume inside a container and run the Docker CLI there, you are talking to the Docker Engine on the host
So what I have to do?
- install inside docker image docker client that will connect to docker daemon running on host (outside docker container)
– Its easy just have to map the host’s
-v /var/run/docker.sock:/var/run/docker.sockto the container’s
- give jenkins user in the container permission to use docker client.
for finding GUID for docker group in host we can use
$getent group docker | cut -d':' -f3
now we have to create similar group in docker container with the same GUID. We have to option how to do it. Inside Dockerfile or create Shell script and use it like entry point.
# RUN addgroup -g $HOST_DOCKER_GROUP_ID docker-host # RUN addgroup jenkins docker-host # RUN adduser jenkins $HOST_DOCKER_GROUP_ID