目录
1.安装Jenkins
参考资料:https://www.jenkins.io/doc/book/installing/docker/#downloading-and-running-jenkins-in-docker
1.Open up a terminal window.(打开一个终端窗口。)
2.Create a bridge network in Docker using the following docker network create command:(使用以下Docker network Create命令在Docker中创建桥接网络)
3.In order to execute Docker commands inside Jenkins nodes, download and run the docker:dind Docker image using the following docker run command:(为了在Jenkins节点内执行Docker命令,请使用以下dockerrun命令下载并运行Docker:dind-Docker映像)
4.获取Jenkins镜像
4.1:Customize the official Jenkins Docker image, by executing the following two steps:Create a Dockerfile with the following content:
4.2:Build a new docker image from this Dockerfile, and assign the image a meaningful name, such as "myjenkins-blueocean:2.401.3-1":
cd 刚才创建Dockerfile目录下执行:来创建镜像
5. Run your own myjenkins-blueocean:2.401.3-1 image as a container in Docker using the following docker run command:(使用以下Docker Run命令在Docker中运行您自己的myjenkins-blueocean:2.401-3-1映像作为容器:)
本篇文章只安装了Jenkins
1.安装Jenkins
参考资料:https://www.jenkins.io/doc/book/installing/docker/#downloading-and-running-jenkins-in-docker
1.Open up a terminal window.(打开一个终端窗口。)
2.Create a bridge network in Docker using the following docker network create command:(使用以下Docker network Create命令在Docker中创建桥接网络)
docker network create jenkins
3.In order to execute Docker commands inside Jenkins nodes, download and run the docker:dind Docker image using the following docker run command:(为了在Jenkins节点内执行Docker命令,请使用以下dockerrun命令下载并运行Docker:dind-Docker映像)
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
If you have problems copying and pasting the above command snippet, use the annotation-free version below:(如果您在复制和粘贴上面的命令片段时遇到问题, 请使用下面的无注释版本)
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
会自动拉取镜像
docker:dind
解释一下这个:可以自行百度
有时需要在容器内执行 docker 命令,比如:在 jenkins 容器内运行 docker 命令执行构建镜像
直接在 docker 容器内嵌套安装 docker 未免太过臃肿
更好的办法是:容器内仅部署 docker 命令行工具(作为客户端),实际执行交由宿主机内的 docker-engine(服务器)
————————————————
4.获取Jenkins镜像
4.1:Customize the official Jenkins Docker image, by executing the following two steps:Create a Dockerfile with the following content:
(通过执行以下两个步骤自定义Jenkins Docker的官方镜像:创建一个包含以下内容的Dockerfile)
创建Dockerfile-内容:
FROM jenkins/jenkins:2.401.3-jdk17
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 docker-workflow"
4.2:Build a new docker image from this Dockerfile, and assign the image a meaningful name, such as "myjenkins-blueocean:2.401.3-1":
(从这个Dockerfile构建一个新的docker映像,并为该映像指定一个有意义的名称,例如“myjenkinsblueocean:2.401-3-1”)
cd 刚才创建Dockerfile目录下执行:来创建镜像
docker build -t myjenkins-blueocean:2.401.3-1 .
If you have not yet downloaded the official Jenkins Docker image, the above process automatically downloads it for you.(如果您还没有下载Jenkins Docker的官方镜像,上述过程会自动为您下载-因为dockerfile里面写了拉取地址)
5. Run your own myjenkins-blueocean:2.401.3-1
image as a container in Docker using the following docker run command:(使用以下Docker Run命令在Docker中运行您自己的myjenkins-blueocean:2.401-3-1映像作为容器:)
docker run \
--name jenkins-blueocean \
--restart=on-failure \
--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.401.3-1
If you have problems copying and pasting the command snippet, use the annotation-free version below:(如果在复制和粘贴命令片段时遇到问题,请使用下面的无注释版本:)
docker run --name jenkins-blueocean --restart=on-failure --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.401.3-1
本篇文章只安装了Jenkins
安装完成访问:http://xxx:8080