In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how springboot integrates docker. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Docker is an open source application container engine based on the Go language and open source according to the Apache2.0 protocol. Docker allows developers to package their applications and dependencies into a lightweight, portable container and publish them to any popular Linux machine. Containers are completely sandboxed and do not have any interfaces to each other (similar to iPhone's app). More importantly, the container performance overhead is extremely low.
Preparatory work
Environment:
Linux environment or mac, do not use windows
Jdk 8
Maven 3.0
Docker
Read the docker tutorial without knowing anything about docker.
Create a springboot project
Introduce the startup dependency of web and create a Controler:
@ SpringBootApplication@RestControllerpublic class SpringbootWithDockerApplication {@ RequestMapping ("/") public String home () {return "Hello Docker World";} public static void main (String [] args) {SpringApplication.run (SpringbootWithDockerApplication.class, args);}} containerize the springboot project
Docker has a simple dockerfile file as the specified mirror layer. Let's first create a dockerFile file:
Src/main/docker/Dockerfile:
FROM frolvlad/alpine-oraclejdk8:slimVOLUME / tmpADD springboot-with-docker-0.0.1-SNAPSHOT.jar app.jarRUN sh-c 'touch / app.jar'ENV JAVA_OPTS= "" ENTRYPOINT ["sh", "- c", "java $JAVA_OPTS-Djava.security.egd=file:/dev/./urandom-jar / app.jar"]
We build the docker image through maven.
In the pom directory of maven, plus the plug-ins built by docker image
Springio com.spotify docker-maven-plugin 0.4.11 ${docker.image.prefix} / ${project.artifactId} src/main/docker / $ {project.build.directory} ${project.build.finalName} .jar
Note: ${docker.image.prefix} is your user name in the official docker warehouse. If you don't need to upload the image, feel free to fill in it.
Through the maven command:
Step 1: mvn clean
Step 2: mvn package docker:bulid, as follows:
Step 2/6: VOLUME / tmp
-→ Running in a98be3878053
-→ 8286e98b54c5
Removing intermediate container a98be3878053
Step 3/6: ADD springboot-with-docker-0.0.1-SNAPSHOT.jar app.jar
-→ c6ce13e50bbd
Removing intermediate container a303a3058869
Step 4 touch 6: RUN sh-c 'touch / app.jar'
-→ Running in cf231afe700e
-→ 9a0ec8936c00
Removing intermediate container cf231afe700e
Step 5ax 6: ENV JAVA_OPTS ""
-→ Running in e192597fc881
-→ 2cb0d73bbdb0
Removing intermediate container e192597fc881
Step 6 java 6: ENTRYPOINT sh-c java $JAVA_OPTS-Djava.security.egd=file:/dev/./urandom-jar / app.jar
-→ Running in ab85f53fcdd8
-→ 60fdb5c61692
Removing intermediate container ab85f53fcdd8
Successfully built 60fdb5c61692
[INFO] Built forezp/springboot-with-docker
[INFO]--
[INFO] BUILD SUCCESS
[INFO]--
[INFO] Total time: 01:45 min
[INFO] Finished at: 2017-04-19T05:37:44-07:00
[INFO] Final Memory: 19M/48M
[INFO]--
The image was built successfully. View the image:
Docker images
Display:
Forezp/springboot-with-docker latest 60fdb5c61692 About a minute ago 195 MB
Start the mirror:
$docker run-p 8080 8080-t forezp/springboot-with-docker
Open a browser to access localhost:8080; browser display: Hello Docker World.
Indicates that the springboot project for docker has been deployed.
Stop mirroring:
Docker stop 60fdb5c61692
Delete the mirror:
Docker rm 60fdb5c61692
After reading the above, do you have any further understanding of how springboot integrates docker? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.