Install Jenkins using Docker

Introduction to Jenkins

Jenkins is an open source continuous integration (DI) tool that is widely used in project development and can provide automatic build, test, deployment and other functions. As the leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.

Official website address: https://www.jenkins.io/

It has the following characteristics:

  • Continuous Integration and Continuous Delivery
  • easy to install
  • easy to configure
  • plug-in function
  • scalability
  • distributed

Jenkins installation

This installation of Jenkins is based on the Docker approach. First pull the Jenkins image.

docker pull jenkinsci/blueocean

# 上面拉取的是最新的镜像,当时最新镜像对应的tag应该是1.25.3,所以你也可以按如下拉取
# docker pull jenkinsci/blueocean:1.25.3

Create a Jenkins working directory and mount the directory in the container to this directory, so that we can synchronize the modification of the file on the host to the container.

mkdir -p /usr/local/jenkins
chmod 777 /usr/local/jenkins

Start the container and map the host and container ports at the same time.

# -d 后台方式启动
# -p 映射端口,宿主机端口:容器内端口
# -v 挂载卷,将容器Jenkins工作目录/var/jenkins_home挂载到宿主机目录/usr/local/jenkins
# -name 给容器起个别名
docker run -d -p 8099:8080 -p 50099:50000 -v /usr/local/jenkins:/var/jenkins_home --name myjenkins jenkinsci/blueocean

Check whether the container starts successfully.

[root@chenpihost local]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS                                                                                      NAMES
538de1b1b1f5   jenkinsci/blueocean   "/sbin/tini -- /usr/…"   18 seconds ago   Up 17 seconds   0.0.0.0:8099->8080/tcp, :::8099->8080/tcp, 0.0.0.0:50099->50000/tcp, :::50099->50000/tcp   myjenkins

Check the Jenkins container logs.

docker logs myjenkins

Add the Jenkins port to the firewall.

firewall-cmd --zone=public --add-port=8099/tcp --permanent
systemctl restart firewalld
firewall-cmd --zone=public --list-ports

Configuring Mirroring Acceleration

Open the file in the Jenkins working directory of the host machine hudson.model.UpdateCenter.xml.

vim /usr/local/jenkins/hudson.model.UpdateCenter.xml

The original content is as follows:

<?xml version='1.1' encoding='UTF-8'?>
<sites>
  <site>
    <id>default</id>
    <url>https://updates.jenkins.io/update-center.json</url>
  </site>
</sites>

The url is changed to the official mirror address of Tsinghua University in China, and the final content is as follows:

<?xml version='1.1' encoding='UTF-8'?>
<sites>
  <site>
    <id>default</id>
    <url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url>
  </site>
</sites>

Restart the Jenkins service.

docker stop 容器ID
docker start 容器ID

Of course, you can also configure mirror acceleration in the advanced settings of the plug-in after logging in to Jenkins, as follows:

1650673746856-ad733f08-a54b-47a8-a173-64e6f0972770.png

Login to initialize Jenkins

When accessing in a browser http://jenkins所在主机ip:8099, it will take some time for the following interface to appear.

1650641268873-5713cfa9-0a15-4b40-a00f-07169fa66bc5.png

After waiting, the following interface appears, and a password needs to be entered.

1650642089658-7938d0c9-5ae5-42c1-8b31-49a6d987f516.png

You can check the host /usr/local/jenkins/secrets/initialAdminPasswordfile to get the password.

cat /usr/local/jenkins/secrets/initialAdminPassword

Or enter the container and view /var/jenkins_home/secrets/initialAdminPasswordthe file to obtain the password.

# 进入容器
docker exec -it 容器ID /bin/bash
# 查看密码
cat /var/jenkins_home/secrets/initialAdminPassword

After entering the password, the following interface appears. It is recommended to choose the first one, and wait for the plug-in to be installed after selection.

1650642148191-cf7d8ab7-ac27-44e2-a1d4-a160d413e560.png

1650642167773-226e463a-24e5-4816-bc5b-d5120a5ca4dd.png

Create a root user and log in.

1650642297724-062acb32-c2f8-4c62-a326-704f2c2a3a84.png

After successful login, enter the following page.

1650642366405-57187eb8-f3b9-49b7-92d1-d5175e67eba8.png

Guess you like

Origin blog.csdn.net/a772304419/article/details/132172946