Use Docker to build Jenkins container in Linux environment

  1. Conditions that need to be prepared in advance

    Maven environment
    Docker environment
    JDK environment (Centos8 comes with JDK environment removed, reinstalled JDK)

Step1: Install the Jenkins image

Use docker to query the jenkins image

docker search jenkins

insert image description here

We choose to download the second one, jenkins/jenkins, download command

docker pull jenkins/jenkins

insert image description here

Use the docker command to view the downloaded Jenkins image

docker images

insert image description here

Step2: docker starts the Jenkins container

Create a mount folder and grant file permissions

#创建挂载文件夹
mkdir -p /home/jenkins_home
#给文件夹授予权限
chmod 777 /home/jenkins_home

Start the Jenkins container

docker run -d -uroot -p 9095:8080 -p 50000:50000 --name jenkins -v /home/jenkins_home:/var/jenkins_home -v /etc/localtime:/etc/localtime jenkins/jenkins
Order illustrate
-d Run the container in the background and return the container ID
jenkins/jenkins The name of the image, and the image ID can also be written here
-uroot Map port 8080 in the container to port 9095 of the host, which is the port for accessing jenkins
-p 50000:50000 Map port 50000 in the container to port 50000 on the host
–name jenkins Set the container name to jenkins
-v /home/jenkins_home:/var/jenkins_home :/var/jenkins_home directory is the container jenkins working directory, we mount a directory on the hard disk to this location, so that the original working directory can be used after updating the image
-v /etc/localtime:/etc/localtime Make the container use the same time settings as the server
jenkins/jenkins The name of the image, and the image ID can also be written here

Check the jenkins log

docker logs jenkins

insert image description here

Step3: Access Jenkins

Enter in the browser: http://server IP address: port/access jenkins, serverIp is the ip of the docker host, and port is the port mapped by the host. mine is:

http://server ip address:9095/

Here we fill in the Jenkins initialization login password in the log just now

insert image description here

Step4: Install the Jenkins plugin

insert image description here

Due to network reasons, the plug-in source needs to be set to domestic, so that the plug-in can be installed. Enter the host directory /home/jenkins_home/, edit the file
hudson.model.UpdateCenter.xml

cd /home/jenkins_home/
cat hudson.model.UpdateCenter.xml

Just replace it with a domestic mirror (here we use the official mirror of Tsinghua University)
and change the url content to https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json (official Tsinghua University mirror image)
insert image description here
insert image description here

Finally we restart the Jenkins container

docker restart jenkins  

After restarting, select the recommended plug-in installation

insert image description here

After the plug-in installation is complete, the Jenkins build is over~

insert image description here

Guess you like

Origin blog.csdn.net/m0_43413873/article/details/125414483