This is the 9th day of my participation in the August More Text Challenge. For details, see:August is more challenging

Docker combined with Jenkins to realize automated project deployment

1. Download Jenkins image

Docker pull Jenkins, by default, if you do not specify a version number and the prefix, the default is to the docker Hub official to download the image, the default version label is the "latest"Copy the code

Note: Windows/Mac requires you to log in to the Boot2docker virtual machine, Linux does not.

docker-machine ssh default
Copy the code

2. Start the Jenkins container

docker run -d -p 28080:8080 --name jenkins -v /opt/jenkins:/var/jenkins_home jenkins

Copy the code

Jenkins’ default port number is 8080, because port 8080 already exists on the host, so I’ll map it to port 28080.

At the same time, the Jenkins data is mounted to the /opt/ Jenkins directory on the host.

If you look at the running container with Docker Ps after running the run command above, you might notice that the Jenkins container did not start successfully.

You can use the docker logs password to view logs for container startup.

docker logs 677
Copy the code

If permission denied occurs

The main cause is the write permission of the file. Here’s an article on the Internet:

Testerhome.com/topics/1193…

/opt/ Jenkins’ /opt/ Jenkins’ /opt/ Jenkins’ /opt/ Jenkins

sudo chown -R 1000:1000 /opt/jenkins
Copy the code

Restart Jenkins container (Docker restart container ID)

Docker Start Jenkins Docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES DAF75FBEC296 Jenkins "/ bin/observatory - / usr/l..." About a minute ago Up 5 seconds 50000/ TCP, 0.0.0.0:28080->8080/ TCP JenkinsCopy the code

Browser open access Jenkins service: http://192.168.99.100:28080/

When you first visit Jenkins, Jenkins assigns you a password to log into the Jenkins system. The red parts are as follows:

The/var/jenkins_home/secrets/initialAdminPassword password, the default storage locations to put the contents of the file copy, enter your password on the page. [Note] : Please enter the Jenkins container and find the corresponding password file, not on the host. Make no mistakeCopy the code
  • Get Jenkins’ login password
Docker exec -it daf /bin/bash Where "daf" is the ID of the Jenkins container Docker ps // View CONTAINER ID docker@default:~$Docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES DAF75fBEC296 Jenkins "/ bin/observatory - / usr/l..." 18 minutes a Up 16 minutes 50000/tcp, 0.0.0.0:28080->8080/ TCP Jenkins docker@default:~$docker exec -it daf /bin/bash jenkins@daf75fbec296:/$ls bin dev etc lib media opt root sbin sys usr boot docker-java-home home lib64 mnt proc run srv tmp var jenkins@daf75fbec296:/$ cat /var/jenkins_home/secrets/initialAdminPassword ce263b7052c049c189582a54094e9afcCopy the code
  • After entering the container, you can directly use the following command to view the password, and then manually copy the password:
cat /var/jenkins_home/secrets/initialAdminPassword
Copy the code

After logging into Jenkins successfully, the following page will first appear:

Getting Started

Customize Jenkins

The one on the left is: Install the recommended software. The right one is: select the software you need to install.

I’m just going to choose the one on the left and just install the software by default.

Enter the relevant account information

  • 1. The localization
Install the plug-in. Locale Plugin Manages the Language. Locale plugin Set the system Settings to locale Default Language zh_CNCopy the code
  • 2. User authorization
Choose System Management > Configure Global Security > Authorization Policy > Project Matrix Authorization PolicyCopy the code
  • 3. User management
Choose System > Manage User > Create UserCopy the code

reference

  • docker-jenkins-springboot-maven-deploy