Docker version 19.03.2
CentOS7.6.1810
IntelliJ IDEA 2019.2
Learning Objectives:
master DockerMaven use plug-ins
to master continuous integration tools Jenkins installation and use of
master container management tools Rancher installation and use of
1 DockerMaven plug
For a large number of micro-services, the actual development of the method used in the enterprise is using DockerMaven plug-ins automatically deploy.
Implement automatic deployment maven plugin, you need to modify the configuration file Docker, the introduction of plug-in pom.xml, and finally uploaded by cmd command line image.
Maven plug-in automatic deployment steps:
( 1 ) modify the host docker configuration, remote access allowed
Docker backup configuration files
cp /lib/systemd/system/docker.service /lib/systemd/system/docker.service.bak
Docker edit the configuration file
we /lib/systemd/system/docker.service
Modify daemon.json
we /etc/docker/daemon.json
Add pair
"hosts": ["0.0.0.0:2375","unix:///var/run/docker.sock"]
( 2 ) refresh configuration, restart the service
systemctl daemon‐reload
systemctl restart docker
docker start registry
( 3 ) in the project pom.xml increase in plug-in configuration
<build> <finalName>app</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring‐boot‐maven‐plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker‐maven‐plugin</artifactId> <version>0.4.13</version> <configuration> <imageName>192.168.184.141:5000/${project.artifactId}:${project.version} </imageName> <baseImage>jdk1.8</baseImage> <entryPoint>["java", "‐jar", "/${project.build.finalName}.jar"]</entryPoint> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory} </directory> <include>${project.build.finalName}.jar</include> </resource> </resources> <dockerHost>http://192.168.184.141:2375</dockerHost> </configuration> </plugin> </plugins> </build>
The above configuration will automatically generate Dockerfile
FROM jdk1.8 ADD app.jar / ENTRYPOINT ["java","‐jar","/app.jar"]
( 4 ) in the windows at the command prompt, enter the engineering tensquare_parent directory is located
mvn install
Enter tensquare_base directory is located, it enters the following command to package and upload image
mvn docker:build ‐DpushImage
(5 ) into the host , to view mirror
docker images
Browser access http://192.168.184.141:5000/v2/_catalog , output
( 6 ) start the container:
docker run ‐di ‐‐name=base ‐p 9001:9001
192.168.184.141:5000/tensquare_base:1.0‐SNAPSHOT
=================================================