Jenkins是一个开源的、提供友好操作界面的持续集成(CI)工具,起源于Hudson(Hudson是商用的),主要用于持续、自动的构建/测试软件项目、监控外部任务的运行(这个比较抽象,暂且写上,不做解释)。Jenkins用Java语言编写,可在Tomcat等流行的servlet容器中运行,也可独立运行。通常与版本管理工具(SCM)、构建工具结合使用。常用的版本控制工具有SVN、GIT,构建工具有Maven、Ant、Gradle。
官方安装文档 Docker in Docker https://www.jenkins.io/doc/book/installing/docker/#downloading-and-running-jenkins-in-docker
On macOS and Linux
1 Open up a terminal window.
2 Create a bridge network
in Docker using the following docker network create
command
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:
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
4 Customise official Jenkins Docker image, by executing below two steps: 4.1 Create Dockerfile with the following content:
FROM jenkins/jenkins:lts-jdk11
USER root
RUN apt-get update && apt-get install -y apt-transport-https \
ca-certificates curl gnupg2 \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable"
RUN apt-get update && apt-get install -y docker-ce-cli
USER jenkins
RUN jenkins-plugin-cli --plugins "blueocean:1.24.7 docker-workflow:1.26"
4.2 Build a new docker image from this Dockerfile and assign the image a meaningful name, e.g. “myjenkins-blueocean:1.1”
docker build -t myjenkins-blueocean:1.1 .
5 Run your own myjenkins-blueocean:1.1
image as a container in Docker using the following docker run command:
docker run -d \
--network jenkins \
-v jenkins_home:/var/jenkins_home \
-v jenkins-docker-certs:/certs/client:ro \
-e DOCKER_HOST=tcp://docker:2376 \
-e DOCKER_CERT_PATH=/certs/client \
-e DOCKER_TLS_VERIFY=1 \
-p 8080:8080 -p 50000:50000 myjenkins-blueocean:1.1