Reputation: 1124
Using the official jenkins image, I have installed docker and docker-compose and added jenkins to the docker group (GID 999 in the container).
After that, I shared the /var/run/docker.sock of the host so enable jenkins create "siblings" containers. It happens that the original file have GID 134 and with this GID is mounted. I am getting the following error:
demo_1 | docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.32/containers/create: dial unix /var/run/docker.sock: connect: permission denied. demo_1 | See 'docker run --help'.
Any idea about how to solve this?
My minimal (and not optimized yet) Dockerfile is:
FROM jenkins/jenkins:lts
USER root
RUN apt-get update && apt-get install -y apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"
RUN apt-get update
RUN apt-get install -y docker-ce docker-compose
RUN usermod -aG docker jenkins
USER jenkins
RUN newgrp docker
I have also created a docker-compose to test it:
version: '2'
services:
demo:
build: .
ports:
- 8080:8080
- 50000:50000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: >
/bin/sh -c "
set -e
groups
docker -v
docker-compose -v
ls -ln /var/run/docker.sock
id jenkins
docker run hello-world
"
The output is:
demo_1 | jenkins staff docker
demo_1 | Docker version 17.09.0-ce, build afdb6d4
demo_1 | docker-compose version 1.8.0, build unknown
demo_1 | srw-rw---- 1 0 134 0 Sep 30 07:36 /var/run/docker.sock
demo_1 | uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins),50(staff),999(docker)
demo_1 | docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.32/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
demo_1 | See 'docker run --help'.
Upvotes: 3
Views: 1093
Reputation: 826
you can create a group in dockerfile with the same group id as docker https://stackoverflow.com/a/71085404/4791684
Upvotes: 0
Reputation: 1124
I gave the problem a dirty fix, so I am letting this question open to see if a better one appears.
As the /var/run/docker.sock file is owned by root, which have the same UID, I added jenkins to the list of sudoers without need to type password:
RUN adduser jenkins sudo
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
This solved the issue. I dislike it, but it works.
Upvotes: 0