Skip to content

Instantly share code, notes, and snippets.

@sbose78
Last active July 9, 2018 06:42
Show Gist options
  • Select an option

  • Save sbose78/881149c8efeaa10c663a34d175e805a9 to your computer and use it in GitHub Desktop.

Select an option

Save sbose78/881149c8efeaa10c663a34d175e805a9 to your computer and use it in GitHub Desktop.
Run docker inside Jenkins

Create a Dockerfile with the following contents

FROM jenkins:2.32.3

USER root
RUN apt-get -qq update \
   && apt-get -qq -y install \
   curl

RUN curl -sSL https://get.docker.com/ | sh

RUN usermod -a -G staff jenkins

USER jenkins

Create an image:

docker build -t jenkins_docker .

Run the container:

docker run -d -p 8080:8080 -p 4040:4040 -v /var/run/docker.sock:/var/run/docker.sock jenkins_docker

Demo: https://drive.google.com/file/d/0Bz8VjLQTuhwvT05wMlFrYnJwZVE/view?usp=sharing

@dom3k
Copy link
Copy Markdown

dom3k commented Jul 9, 2018

This code does not work.
Docker version: 17.12.1-ce
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.37/version: dial unix /var/run/docker.sock: connect: permission denied
This work only when USER root, not USER jenkins.
Any ideas?

@dom3k
Copy link
Copy Markdown

dom3k commented Jul 9, 2018

Ok it is working now. Docker group id must be the same on host and container machine.
Helpful commands:
get group id:
getent group docker
set group id:
groupmod -g 3000 docker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment