docker network create jenkins
docker run --name jenkins-docker --rm --detach \
--privileged --network jenkins --network-alias docker \
--env DOCKER_TLS_CERTDIR=/certs \
--volume path/to/jenkins-docker-certs:/certs/client \
--volume path/to/jenkins-data:/var/jenkins_home \
--publish 2376:2376 \
docker:dind --storage-driver overlay2
FROM jenkins/jenkins:2.332.2-jdk11
USER root
RUN apt-get update && apt-get install -y lsb-release
RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc \
https://download.docker.com/linux/debian/gpg
RUN echo "deb [arch=$(dpkg --print-architecture) \
signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \
https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
RUN apt-get update && apt-get install -y docker-ce-cli
USER jenkins
RUN jenkins-plugin-cli --plugins "blueocean:1.25.3 docker-workflow:1.28"
FROM jenkins/jenkins:latest
USER root
# apt 换源用,事先准备好 sources.list
COPY sources.list /etc/apt/
# pip 换源用,事先准备好 pip.conf
RUN mkdir -p /home/jenkins/.pip/
RUN mkdir -p /root/.pip/
# docker 换源用,事先准备好 daemon.json
RUN mkdir -p /etc/docker/
COPY daemon.json /etc/docker/
COPY pip.conf /home/jenkins/.pip/
COPY pip.conf /root/.pip/
# 内部安装 docker 包,需事先准备好 docker/docker-ce-cli_20.10.14_3-0_debian-bullseye_amd64.deb
COPY docker/ /tmp/docker/
RUN apt-get update && apt-get install -y apt-utils && apt-get install -y lsb-release sudo iptables libdevmapper1.02.1 dbus-user-session
RUN dpkg -i /tmp/docker/docker-ce-cli_20.10.14_3-0_debian-bullseye_amd64.deb
# 导入 maven 及其配置,需事先准备好 apache-maven-3.8.5-bin.tar.gz 和 settings.xml
ADD apache-maven-3.8.5-bin.tar.gz /usr/local/
COPY settings.xml /usr/local/apache-maven-3.8.5/conf/
USER jenkins
docker build -t my-jenkins .
docker run \
--name jenkins \
--rm \
--detach \
--network jenkins \
--env DOCKER_HOST=tcp://docker:2376 \
--env DOCKER_CERT_PATH=/certs/client \
--env DOCKER_TLS_VERIFY=1 \
--publish 8080:8080 \
--publish 50000:50000 \
--privileged=true \
--volume path/to/jenkins-data:/var/jenkins_home \
--volume path/to/jenkins-docker-certs:/certs/client:ro \
my-jenkins
Docker