In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the detailed process of deploying SpringBoot project in Docker". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the detailed process of deploying a SpringBoot project in Docker.
Create a Spring Boot program
In this article, we will run a simple SpringBoot Web application in a Docker container. Here are the contents of the initial pom.xml.
4.0.0 cn.itweknow springboot-docker 0.0.1-SNAPSHOT jar springboot-docker Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 2.1.0.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin
Add a HelloController.java
RestControllerpublic class HelloController {@ RequestMapping ("/ hello") public String hello () {return "Hello Docker.";}}
Well, so far we have built a simple web application that can run locally and see the results to make sure the program is correct.
Configure Docker
Docker provides the plug-in docker-maven-plugin built by maven, we just need to add this plug-in to our pom.xml, and then do some related simple configuration on OK.
Com.spotify docker-maven-plugin 1.2.0 itweknow/$ {project.artifactId} java:8 ["java", "- jar", "/ ${project.build.finalName} .jar"] / ${project.build.directory} ${project.build.finalName} .jar
Yes, it's as simple as that. so far, our whole project has been set up, and the remaining work is to generate a docker image from the project copy to our linux environment and then run it.
Build an image
After the copy project is under linux, go to the project directory, execute the following command sequentially, and you can generate a docker image.
Mvn clean#-Dmaven.test.skip=true skips the test code mvn package-Dmaven.test.skip=truemvn docker:build
Of course, you can also carry out three orders together.
Mvn clean package docker:build-Dmaven.test.skip=true
Then check the docker image in the system before executing docker images to see if it is generated successfully.
REPOSITORY TAG IMAGE ID CREATED SIZEitweknow/springboot-docker latest f03b689cfc33 10 seconds ago 660MB
Run the Docker container
#-d is the specified background operation #-name is the specified container name #-p 8080 name 8080 refers to the mapping of the container's port 8080 to the host's port 8080 format: host (host) port: container port docker run-d-name test-p 8080pur808080 itweknow/springboot-docker
Execute docker ps to check the container that is running
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES652fd3ccac89 itweknow/springboot-docker "java-jar / springbo..." 3 seconds ago Up 2 seconds 0.0.0.0purl 8080-> 8080/tcp test
Our project has been successfully run in the docker container, and we can visit the http:// virtual machine IP:8080/hello to test it.
At this point, I believe you have a deeper understanding of "the detailed process of deploying a SpringBoot project in Docker". 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.