Docker inside Jenkins container

Hi there.

I have been searching for a solution but without any luck.

I want to use a Jenkins container for a series of docker-related jobs. For that, I am trying to mount the docker socket into my container.

I successfully manage to start my jenkins container with the following params:

docker run --name jenkins --privileged=true -t -i --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/bin/docker -p 8080:8080 jenkins

the docker command is detected successfully. However, when I try a simple command inside the container like

docker version
Client:
Version: 1.8.2
API version: 1.20
Go version: go1.4.2
Git commit: 0a8c2e3
Built: Thu Sep 10 19:19:00 UTC 2015
OS/Arch: linux/amd64
Get http:///var/run/docker.sock/v1.20/version: dial unix /var/run/docker.sock: permission denied.

  • Are you trying to connect to a TLS-enabled daemon without TLS?
  • Is your docker daemon up and running?

What am I missing? I have added the jenkins user to the docker group.

I’m doing something similar - and its working for me

because I want the Jenkins container to work with any docker.sock, I’m using a script like
https://github.com/SvenDowideit/docs-automation/blob/master/jenkins/setup-docker-and-start-jenkins.sh to create the docker group in the jenkins container, and then add the jenkins user to it.

perhaps the container’s docker group does not match the host’s one?

or maybe you have SELinux, and need to give the container SELinux permission to access the HOST’s socket.

3 Likes

Thanks sven, that almost did the trick.

I just needed to add

RUN chmod +x

after the copy command and all worked fine.