Automated deployment (CONTINUOUS integration /CI+ Continuous delivery /CD) can not only improve development efficiency and enable programmers to focus on product and business development, but also save a lot of operation and maintenance costs and improve operation and maintenance efficiency. Among them, Jenkins is the most popular tool in automated deployment, especially the perfect combination of Docker+Jenkins, every programmer should master the use of these two tools.

Environment configuration

CentOS Linux release 7.6.1810 Docker version: 19.03.5 Jenkins version: 2.204.1Copy the code

Docker installation Jenkins

Docker download Jenkins

Docker Pull Jenkins/Jenkins: LTS // Latest versionCopy the code

View Jenkins mirror

Docker images Docker inspect Jenkins Image IDCopy the code

Create a Jenkins directory

mkdir /data/jenkins_home;
Copy the code

Install and start Jenkins container

docker run -d--name jenkins -p 8081:8080 -v /data/jenkins_home:/var/jenkins_home jenkins/jenkins:lts; Remark:-d--name // Container name -p // Port mapping (8081: host host port, 8080: container internal port) -v // Data volume mounting mapping (/data/ jenkins_HOME: Enkins /Jenkins: LTS //Jenkins mirror (latest version)Copy the code

Check Jenkins startup status

docker ps | grep jenkins;
Copy the code

Minor problems encountered during installation

The Jenkins container docker run state is always Exited

The /data/jenkins_home directory is rootCopy the code

Solution: chown -r 1000:1000 /data/jenkins_home // User group changesCopy the code

The host host port must be enabled

Because this operation is installed on aliyun ECS, port 8081 needs to be opened in the security group.Copy the code

Visit Jenkins

http://120.26.50.165:8081 / / IP: port numberCopy the code

Managing Jenkins configuration

unlock

After the installation is complete, a login password is generated by default. This password is required for the first login. Password path: / var/jenkins_home secrets/initialAdminPassword / / container inside find password: dockerexec- it jenkins_01 bash / / into the cat/var/Jenkins container jenkins_home/secrets/initialAdminPassword / / view the passwordCopy the code

Installing a plug-in

Recommended Install suggested plugins for beginners. The installation takes about half an hour.Copy the code

Managing User Creation

This user is the maximum administrator, which is equivalent to adminCopy the code

Jenkins configuration complete

At this step, the installation is done! http://120.26.50.165:8081 / / IP: port numberCopy the code

Automated deployment

With Jenkins, the next step is to automate the code deployment process.Copy the code

Docker+ LNMP +Jenkins+ code cloud for automatic deployment of PHP code