Docker installation and configurationMove Docker installation and configuration
Table of contents
5. Configure Git warehouse to pull code and build
1. Pull the Jenkin image
docker pull jenkins
You can view the image with the following command
[root@VM-12-8-centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins/jenkins latest b66997a14a0c 2 days ago 466MB
2. Run and start Jenkins
docker run -d
--name jenkins
-p 9999:8080
-p 50000:50000
-v /home/jenkins_home:/var/jenkins_home
jenkins/jenkins
Remember to open the corresponding port in the firewall
illustrate:
Order | effect |
-d | Container running in the background |
--name jenkins | Container name |
-p 9999:8080 | Bind the host port 9999 to the container's port 8080. Port 8080 is the default port of the Jenkins Web interface. |
-p 50000:50000 | Bind the host's 50000 port to the container's 50000 port. Port 50000 is the default agent node (Agent) communication port of Jenkins. |
-v /home/jenkins_home:/var/jenkins_home | Mount the jenkins workspace directory to the host /home/jenkins_home |
jenkins/jenkins | Build jenkins container version |
Note: If you need to deploy a Java project, you need to install JDK and Maven on the server, and you need to add the following startup items. If you only deploy static web pages or PHP projects, there is no need to configure JDK and Maven .
Order | effect |
-v /usr/local/src/jdk/jdk1.8:/usr/local/src/jdk/jdk1.8 | Using the build command in Jenkins to restart the jar package requires the use of JDK and needs to be mounted to the real JDK directory on the server. |
-v /opt/apache-maven-3.5.0:/opt/apache-maven-3.5.0 | Mount the Maven directory on the server |
Check whether Jenkins started successfully
[root@VM-12-8-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9684f2939fc1 jenkins/jenkins "/usr/bin/tini -- /u…" 27 hours ago Up 4 hours 0.0.0.0:9999->8080/tcp, :::9999->8080/tcp, 0.0.0.0:50000->50000/tcp, :::50055->50000/tcp jenkins
3.Access Jenkins
Access service ip + configure Jenkins port 9999
We need to enter the container to view the file to obtain the administrator password. There are two ways:
1. Check the log
[root@VM-12-8-centos ~]# docker logs 容器ID/容器名称
You can see a string of randomly generated passwords in the log, such as: 18aec8b1dac249e55485fef473p4e62b
2. View the password file
[root@VM-12-8-centos ~] docker exec my-jenkins cat /var/jenkins_home/secrets/initialAdminPassword
4. Configure Jenkins
Plug-in download
Enter system management on the left side of the Jenkins interface, and then enter plug-in management:
Download the Chinese plug-in: Localization: Chinese (Simplified) (the container needs to be restarted to take full effect)
Download the gitee plug-in: G itee
Configuration
If you are deploying a Java project, you need to configure the addresses of Maven and JDK in System Management->System Configuration.
Because Jenkins is run by docker, it cannot directly run the host's commands, so the packaged script needs to be executed by the host, and you need to download the plug-in Publish Over SSH.
Then configure SSH related information in Publish over SSH in the system configuration
5. Configure Git warehouse to pull code and build
1. Return to the homepage and click New Task.
2. Use a customized workspace (be sure to select the mounted data volume)
3. Configure Gitee in source code management
4. To build the trigger, you only need to fill in the Gitee WebHook password and URL generated by Jenkins into the WebHook of the corresponding warehouse in Gitee.
5. If you are deploying a Java project, you need to configure additional packaging commands and add shell commands to be executed after the build is completed. You can refer to other articles for configuration.
6.Save
6. Test the build
Return to the home page, click on the task you just created, and click Build Now.
Wait for a while, go to the server to check the directory mounted to the host, and find that Jenkins has completed automatic deployment.