获取最新jenkins镜像到本地
docker pull jenkins
root@sator: / home/ sator# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins latest cd14cecfdb3a 3 years ago 696 MB
创建工作目录
root@sator: / home/ sator# mkdir - p / home/ sator/ docker/
root@sator: / home/ sator# mkdir - p / home/ sator/ jenkins_home
chmod 755 / home/ sator/ jenkins_home
root@sator: / home/ sator# docker network create jenkins
b886afddbb669bf9e4a24637f769d01b200c7544066c788f3122ffb914bb1649
运行镜像docker:dind
docker run
-- name jenkins- docker -- rm -- detach
-- privileged -- network jenkins
-- network- alias docker
-- env DOCKER_TLS_CERTDIR = / certs
-- volume jenkins- docker- certs: / certs/ client
-- volume jenkins- data: / var / jenkins_home
-- publish 2376 : 2376
docker: dind -- storage- driver overlay2
自定义官方 Jenkins Docker 镜像
FROM jenkins/ jenkins: 2.332 .1 - 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"
docker build - t myjenkins- blueocean: 2.332 .1 - 1 .
将镜像作为容器
docker run \
-- name jenkins- blueocean \
-- 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 \
-- volume jenkins- data: / var / jenkins_home \
-- volume jenkins- docker- certs: / certs/ client: ro \
myjenkins- blueocean: 2.332 .1 - 1
``