- Create a Dockerfile
FROM jenkins/jenkins:lts
USER root
RUN apt-get update \
&& apt-get install -y sudo \
&& rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
USER jenkins
We need to give the jenkins user sudo privileges in order to be able to run Docker commands inside the container.
- Build your jenkins container
$ docker build -t my_jenkins .
- Run your container
$ docker run -d -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -p 8080:8080 -p 50000:50000 my_jenkins
- Once your container is running, navigate to
http://localhost:8080
, install the default plugins and setup your Jenkins admin. - Go to
Manage Jenkins
->Manage Plugins
. Under theAvailable
tab search fordocker
and installDocker
andDocker Pipeline
plugins. - Create a pipeline (Freestyle or Multibranch pipeline) and test!
- If you get
Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
, try these: - Add
jenkins
user to the docker group and restart the Jenkins:
$ sudo usermod -a -G docker jenkins
$ sudo service jenkins restart
You can check it was successful by doing grep docker /etc/group and see something like this:
docker:x:998:jenkins
Then change your users group ID to docker:
newgrp docker
Finally, log out and log in again.
Use DIND instead