In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to use dockerfile-maven-plugin". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use dockerfile-maven-plugin.
Catalogue
Pom configuration
Setting.xml configuration
Login situation
Login required
No need to log in
Maven multi-module configuration
Jenkins
Jenkins server installs docker
Modify jenkins project configuration
Recently, when deploying the application to the container platform, you need to generate a docker image when packaging. The plug-in docker-maven-plugin was first found on the Internet, but it is very troublesome to use, and you have to do a lot of additional configuration in both maven and dockfile. Later, I saw in the official Github that the author recommended dockerfile-maven-plugin as a new plug-in, so I replaced it with this one, but there is little information about this plug-in on the Internet. Record it here.
Pom configuration org.apache.maven.plugins maven-deploy-plugin true com.spotify dockerfile-maven-plugin 1.4.10 Docker -reg.****.com/feedback/$ {artifactId}-${profiles.active} ${project.version} target/$ {project.build.finalName} .jar setting.xml configuration
This file is in the maven directory and can be accessed by cd $M2_HOME/conf.
Add a com.spotify to pluginGroups
Login is required for com.spotify login
There are many pits on how to verify login. If you set your repository private in habor, you must log in, according to the official configuration, as follows.
Com.spotify dockerfile-maven-plugin ${version} repoUserName repoPassword ${docker.image.prefix} / ${project.artifactId} target/$ {project.build.finalName} .jar need not be logged in
However, because I have configured to automatically obtain images from habor at K8s, I have set publicity. In this case, there is no need to log in, but sometimes the execution will fail. In this case, you need to delete the configuration of this website in ~ / .docker / config.json.
Cat ~ / .docker / config.json {"auths": {"192.168.87.110 auth 5000": {"auth": "YWRtaW46JKDtaW4xMjM="} (delete here)}, "HttpHeaders": {"User-Agent": "Docker-Client/18.09.0 (linux)"}}
After confirming that this place is empty, if you still report an error, you can execute docker login again. That's how it works.
Maven multi-module configuration
In the case of multiple modules, the packaging plug-in must be placed in the Application sub-module, if placed in the root pom will result in packaging will not be successful.
The situation is as follows:
-app
-common
-file
-application
-pom.xml
In this case, we can take two steps.
The first step is to package all the modules in the root directory
Mvn clean package-P test
The second step is to execute the deploy command in the sub-module in which you want to package the image
Mvn dockerfile:build dockerfile:push
In this way, the submodule can be successfully packaged as a mirror and push.
Jenkins
After testing locally, get the process to jenkins and do some configuration.
Jenkins server installs docker
As I will not repeat here, the setting.xml and other configurations of maven are the same as those locally.
Modify jenkins project configuration
At this point, because the project needs to be packaged twice (once in the root directory and the second time as a mirror in the subdirectory), the mvn command needs to be executed twice, which is not the same as before, so the first execution is still using jenkins's Build module.
The second execution is placed in post steps through the command to execute
Cd submodule directory mvn clean package-P $env dockerfile:build dockerfile:push
In this way, you can complete the steps of packaging and making an image.
At this point, I believe you have a deeper understanding of "how to use dockerfile-maven-plugin". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.