Recently, when deploying an application to a container platform, I needed to generate a docker image when packaging. I first searched for the docker-maven-plugin plug-in on the Internet, but it was very troublesome to use, and I had to do a lot of extra configuration in maven and dockerfile. Later, I saw on the official Github that the author recommended the use of the new plug-in dockerfile-maven-plugin, so I replaced it with this one, but there is little relevant information about this plug-in on the Internet. Record it here pom configuration<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> <!-- Dockerfile maven plugin --> <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>1.4.10</version> <executions> <!--<execution>--> <!--<id>default</id>--> <!--<goals>--> <!--<!–If you don't want to use docker packaging, comment out this goal–>--> <!--<goal>build</goal>--> <!--<goal>push</goal>--> <!--</goals>--> <!--</execution>--> </executions> <configuration> <repository>docker-reg.****.com/feedback/${artifactId}-${profiles.active}</repository> <tag>${project.version}</tag> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin> Setting.xml configurationThis file is in the Maven directory and can be accessed by cd $M2_HOME/conf. Add a com.spotify in pluginGroups <pluginGroups> <pluginGroup>com.spotify</pluginGroup> </pluginGroups> Login statusLogin requiredThere are many pitfalls in how to verify login. If you set your warehouse to private in habor, you must log in and follow the official configuration as follows. <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>${version}</version> <configuration> <username>repoUserName</username> <password>repoPassword</password> <repository>${docker.image.prefix}/${project.artifactId}</repository> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin> No login requiredBut because I configured k8s to automatically obtain the image from habor, I set it to public. In this case, there is no need to log in, but sometimes the execution fails. At this time, you need to delete the configuration of this website in ~/.docker/config.json. cat ~/.docker/config.json { "auths": { "192.168.87.110:5000": { "auth": "YWRtaW46JKDtaW4xMjM=" }(delete here) }, "HttpHeaders": { "User-Agent": "Docker-Client/18.09.0 (linux)" } } After confirming that this is empty, if an error is still reported, you can execute docker login ... again, and it will succeed. Maven multi-module configurationIn the case of multiple modules, the packaging plug-in must be placed in the Application submodule. If it is placed in the root pom, packaging will fail. The following situations:
In this case, we can divide it into two steps The first step is to package all modules in the root directory mvn clean package -P test The second step is to execute the deploy command in the submodule to package the image mvn dockerfile:build dockerfile:push In this way, the submodule can be successfully packaged into a mirror and pushed. JenkinsAfter testing locally, you need to move this process to Jenkins and do some configuration. Install Docker on Jenkins ServerI will not go into details here. Maven's setting.xml and other configurations are the same as local ones. Modify the Jenkins project configurationAt this point, since the project needs to be packaged twice (once in the root directory and the second time in the subdirectory as a mirror), the mvn command needs to be executed twice, which is different from before, so the first execution still uses the Jenkins Build module. The second execution is placed in the post steps and executed by command cd submodule directory mvn clean package -P $env dockerfile:build dockerfile:push In this way, you can complete the steps of packaging and making images. This is the end of this article about the dockerfile-maven-plugin usage guide. For more information about the use of dockerfile-maven-plugin, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to handle long data when displaying it in html
>>: Introduction to JavaScript strict mode use strict
Forms in HTML can be used to collect various type...
Table of contents 1. Connection Management 2. Imp...
Table of contents 1. Plugins 2. Interlude 3. Impl...
Because the router at home forced to reduce the b...
Table of contents 1. Open source warehouse manage...
This article shares the specific code for WeChat ...
Table of contents Written in front router.json Ro...
Pixel Resolution What we usually call monitor res...
Copy code The code is as follows: <style type=...
The full name of Blog should be Web log, which mea...
Table of contents Slow query basics: optimizing d...
Table of contents 1. Static implementation method...
background When you open the product details on s...
Table of contents Primary key constraint Unique C...
Create a user: create user 'oukele'@'...