docker run -d \
-v jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
-p 8080:8080 -p 50000:50000 \
--name jenkins \
jenkins/jenkins:lts
- use
jenkins:lts
, read https://github.com/jenkinsci/docker/blob/master/README.md - mount the host machine's Docker socket in the container
/var/run/docker.sock:/var/run/docker.sock
, read https://getintodevops.com/blog/the-simple-way-to-run-docker-in-docker-for-ci - name it
jenkins
, important later
- spawn shell of container, however use method recommended here: from https://stackoverflow.com/a/54723144
docker exec -t -i -u root jenkins /bin/bash
- install docker binaries inside the container, note: docker is still used from the host socket! read https://getintodevops.com/blog/the-simple-way-to-run-docker-in-docker-for-ci
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
# inside jenkins container:
usermod -a -G docker jenkins
docker restart jenkins