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 > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to deploy an application in a docker container". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to deploy an application in a docker container".
A simple Hello World application.
1.1 Maven dependence
Org.springframework.bootspring-boot-starter-parent1.5.4.RELEASE
Introduce spring-boot-starter-web to create a Web application.
Org.springframework.bootspring-boot-starterorg.springframework.bootspring-boot-starter-testtestorg.springframework.bootspring-boot-starter-web
1.2 main application
@ SpringBootApplicationpublic class FirtSpringBootApplication {public static void main (String [] args) {SpringApplication.run (FirtSpringBootApplication.class, args);}}
1.3 Service Interface
RESTful service interface:
@ RestControllerpublic class HelloController {@ RequestMapping ("/ hello") public String hello () {return "Hello World";}}
2 install Docker. After installation, the virtual IP of Docker environment is 192.168.99.100.
3 deploy applications
3.1Packaging Spring Boot applications
Execute the mvn packaging command under the Spring Boot application project directory:
Mvn package spring-boot:repackage
A jar package firtSpringBoot-0.0.1-SNAPSHOT.jar is generated in the target directory of the project. Upload the jar package to firtSpringBoot-1.0.jar to the Docker environment.
3.2 Dockerfile Fil
Dockfile is in principle a batch file that contains commands to build the image. Putting these commands in a file is not absolutely necessary because we can pass them to the command line, but it is easier to use the file.
Now create a Dockerfile:
FROM alpine:edgeMAINTAINER peterwanghao.comRUN apk add-- no-cache openjdk8VOLUME / tmpADD firtSpringBoot-1.0.jar firtSpringBoot.jarEXPOSE 8080ENTRYPOINT ["java", "- jar", "/ firtSpringBoot.jar"]
3.3 create a mirror
Run the docker build command from the Dockerfile file directory, which downloads the base image and runs the entries in the Dockerfile file one by one. The name of the created image is first, label 1. 0. -rm=true, delete the container of the intermediate link after the whole construction process is successful.
Docker build-t first:1.0-- rm=true.
Use the docker images command to list all the images and their details.
Docker@default:~/first-spring-boot$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEfirst 1.0 02f67d8c308d 17 hours ago 119MBhello-world latest e38bc07ac18e 6 weeks ago 1.85kBalpine edge 5c4fa780951b 4 months ago 4.15MB
3.4 run the container
Next, we will run the container. Use the following command to load and run the container.
Docker run-name=first-p 8080R 8080-t first:1.0
Use the docker ps command to list running containers
Docker@default:~/first-spring-boot$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9fc3aef6e852 first:1.0 "java-jar / firtSpri 5 hours ago Up 5 hours 0.0.0.0 hours ago Up 5 hours 0.0.0.0 hours ago Up 8080-> Thank you for reading. This is the content of" how to deploy an Application in a docker Container ". After studying this article, I believe you have a deeper understanding of how to deploy an application in a docker container. The specific use situation still needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.