I am trying to run a Jenkins host inside a Docker container for my college’s final paper.
My pipeline will also spawn more containers, and for that, I am binding the /var/run/docker.sock
file, to share the Docker host’s socket with Jenkins and spawn ‘sibling’ containers.
Here is my Jenkins host’s image:
FROM jenkins/jenkins:lts
USER root
RUN apt-get update -qq
&& apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository
"deb [arch=amd64] https://download.docker.com/linux/debian
$(lsb_release -cs)
stable"
RUN apt-get update && apt-get -y install docker docker-ce-cli
RUN groupadd -g 1001 docker
RUN usermod -aG docker jenkins
USER jenkins
In my docker host, the ownership of the docker.sock
file is root:docker
.
However, when I bind the docker.sock
file to the Jenkins host container, it changes the ownership of the file to root:root
(root user, root group), making Jenkins unable to access it, so I get a permission denied error:
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.24/containers/json: dial unix /var/run/docker.sock: connect: permission denied
I can manually change the docker.sock
file’s group to the docker
group so that jenkins
user can access it, with this command:
chgrp docker /var/run/docker.sock
And that works perfectly! But, for some reason, it does not persist after a system/engine restart 🙁
I don’t know if this is a bug with Docker of if I’m doing something wrong.
My greatest concern in this project is security. I don’t want to run containers with root access because I read this is a security risk, neither do I want to manually change docker.sock
permissions everytime I boot my machine.
I am strongly considering moving to the Sysbox approach, even though I still don’t know much about it and what problems I would have.
-
I am using Windows and running Docker Desktop v4.29.0
-
My engine version is 26.0.0 (WSL2)
Any help is appreciated. Thanks in advance!
Tried to run docker ps
command inside my Jenkins container. It should return all currently running containers. Instead, it returns permission denied error.
Jorge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.