I am trying to mount the docker.sock into my jenkins container, so that it has access to the docker instance.
This is my Dockerfile:
FROM jenkins/jenkins:lts
USER root
RUN apt-get update && \
apt-get -y install apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common && \
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey && \
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable" && \
apt-get update && \
apt-get -y install docker-ce
RUN usermod -a -G docker jenkins
USER jenkins
I then start the contaienr with the the docker.sock mount:
docker run -v /var/run/docker.sock:/var/run/docker.sock --name jenkins jenkins/jenkins:lts
If I then go into the container as root (docker exec -it --user root jenkins bash
) i can run docker ps
without any trouble and I see all the containers which are running on the outside docker instance.
But if I the change to the jenkins user and run docker ps
I get:
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied
Even though I ran usermod -a -G docker jenkins
in the Dockerfile.
Does anyone know how to fix it so that the jenkins user also can run the docker commands?