In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what are the differences between Spring Boot's Docker packaging plug-ins". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Spring Boot Docker
In Spring Boot applications, we can agree on different identities to define different environments. For example, dev represents the development environment, test represents the test environment, and the corresponding configuration files are application-dev.yaml and application-test.yaml. We activate the corresponding environment configuration by declaring spring.profiles.active, such as spring.profiles.active=dev when activating the dev environment. The complete startup command is:
Java-Djava.security.egd=file:/dev/./urandom-Dspring.profiles.active=dev-jar spring-boot-app.jar
Write a Dockerfile that can adapt to multiple environments according to the above command:
# introduce openjdk image FROM adoptopenjdk/openjdk8 # declare author LABEL AUTHOR=felord OG=felord.cn # mount several useful folders such as log VOLUME ["/ tmp" "/ logs"] # declares an environment parameter to dynamically enable the configuration file default dev ENV ACTIVE=dev # expose port EXPOSE 8080 # copy and modify the application packaged jar file name ADD / target/flyway-spring-boot-1.0.0.jar app.jar # the first command that runs when the container starts is used to launch the application ENTRYPOINT ["java", "- Djava.security.egd=file:/dev/./urandom" "- Dspring.profiles.active=$ {ACTIVE}", "- jar", "app.jar"]
In this way, the packaged Docker image can be added through docker run to dynamically change the environment-- env ACTIVE=test. Simply writing Dockerfile is not convenient for us to DevOps.
Docker image lifecycle
We need to be able to automatically build, push to the warehouse, pull images, and run a series of pipelined operations. Fortunately, there are many tools on the market to help us achieve this process.
Spring-boot-maven-plugin
This is the official plug-in for Spring Boot, which provides Docker image building capabilities in a version of 2.x.
Org.springframework.boot spring-boot-maven-plugin docker.repo.com/library/$ {project.artifactId}: ${project.version} true user secret https://docker.repo.com/v1/ user@example.com
After the Docker private warehouse is configured, you can build the image through mvn clean spring-boot:build-image.
The advantage of this approach is that there is no extra dependency, but the disadvantage is that you need to download the build components from github, and if the network is not good, it is easy to fail.
Spotify Maven Plugin
The Spotify Maven plug-in is a common choice at present. It requires application developers to write Dockerfile and place Dockerfile in the project src/main/docker directory. Then you can introduce:
Com.spotify dockerfile-maven-plugin 1.4.8 repo.com/$ {project.artifactId}
This plug-in provides mvn dockerfile:build, mvn dockerfile:tag, and mvn dockerfile:push commands for building, tagging, and publishing to remote private repositories, which is very simple.
This is a very easy to use plug-in, the only requirement is to be able to write Dockerfile, high requirements for customization can use this.
Jib Maven Plugin
I have already introduced this in an earlier article, so you can learn more about it. It is Google's open source OCI image packaging tool, can be used to package Docker images, in most cases has met the needs. But if you want to customize it is not easy, you need to read the official documentation. The original Dockerfile needs to be configured like this if you use JIb:
Com.google.cloud.tools jib-maven-plugin 3.0.0 adoptopenjdk/openjdk8 docker.repo.com/library/$ {project.artifactId} felord xxxxxx ${project.version} Target/$ {project.artifactId}-${project.version} .jar * .jar / app.jar packaged / tmp / logs 8080 dev java,-Djava.security.egd=file:/dev/./urandom,-Dspring.profiles.active=$ {active},-jar,/app.jar USE_CURRENT_TIMESTAMP
The advantage is that it does not require a local Docker environment, and supports hierarchical construction and image slimming, which makes it easy to get started; the disadvantage is that customization is difficult.
This is the end of the content of "what are the differences between Spring Boot's Docker packaging plug-ins". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.