Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy springboot Integration docker to implement two ways to build Docker Images

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "springboot integration docker how to deploy to achieve two ways to build Docker image", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "springboot integration docker how to deploy to achieve two ways to build Docker image" this article.

Docker is an open source engine that can easily create a lightweight, portable, self-sufficient container for any application. Containers that developers compile and test on notebooks can be deployed in batches in production environments, including VMs (virtual machines), bare metal, OpenStack clusters and other basic application platforms.

Application scenarios of docker

Automatic Packaging and Distribution of web applications

Automated testing and continuous integration, release

Deploy and adjust databases or other background applications in a service-oriented environment

Build your own PaaS environment by compiling or extending existing OpenShift or Cloud Foundry platforms from scratch.

Project structure

Package hello;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@SpringBootApplication@RestControllerpublic class Application {@ RequestMapping ("/") public String home () {return "Hello Docker World";} public static void main (String [] args) {SpringApplication.run (Application.class, args) }} server: port: 8010#TODO: figure out why I need this here and in bootstrap.ymlspring: application: name: testLatticeAppribbon: ServerListRefreshInterval: 1000endpoints: health: sensitive: false restart: enabled: true shutdown: enabled: true

Dockfile

FROM frolvlad/alpine-oraclejdk8:slimVOLUME / tmpADD gs-spring-boot-docker-master-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"]

Explain this configuration file:

VOLUME specifies the temporary file directory as / tmp. The effect is to create a temporary file in the host / var/lib/docker directory and link to the container's / tmp. The change steps are optional, which is necessary if the application of the file system is involved. The / tmp directory is used to persist to the Docker data folder, because the embedded Tomcat container used by Spring Boot default uses / tmp as the working directory project's jar file to be added as "app.jar" to the container's ENTRYPOINT to execute the project app.jar. To shorten the Tomcat startup time, add a system property pointing to "/ dev/urandom" as Entropy Source

Pom.xml

4.0.0 gs-spring-boot-docker-master gs-spring-boot-docker-master 0.0.1-SNAPSHOT jar org.springframework.boot spring-boot-starter-parent 2.0.2.RELEASE UTF-8 UTF-8 springio 1.8 org.springframework.boot spring-boot-maven-plugin com.spotify docker-maven-plugin 0.4.13 ${docker.image. Prefix} / ${project.artifactId} src/main/docker / ${project.build.directory} ${project.build.finalName} .jar org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test

Detailed explanation of Dockfile configuration file

VOLUME specifies the temporary file directory as / tmp. The effect is to create a temporary file in the host / var/lib/docker directory and link to the container's / tmp. The change steps are optional, which is necessary if the application of the file system is involved. The / tmp directory is used to persist to the Docker data folder because the embedded Tomcat container used by Spring Boot uses / tmp as the working directory by default

The project's jar file is added as "app.jar" to the container's

ENTRYPOINT executes the project app.jar. To shorten the Tomcat startup time, add a system property pointing to "/ dev/urandom" as Entropy Source

Run the program in non-Docker mode

Use the Maven command

Mvn package

Run: java-jar target/lidong-spring-boot-demo-1.0-SNAPSHOT.jar

Access to the project

If the program runs correctly, the browser accesses http://localhost:8081/ and you can see the page "Hello Docker World." Words.

Start deploying the springBoot project in docker (method 1)

1. Create a folder docker in centos7 ~ to place the project docker_spring_boot.jar packaged by Dockerfile and springBoot above

two。

Under the docker file, command: docker build-t docker.

Execute the docker build command, and docker will build a new image based on the commands you defined in Dockerfile.

-t represents the tag,. of the image to be built Represents the current directory, that is, the directory where Dockerfile is located. Then you can see that after downloading various dependent maven, various jar, and building, start the project.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report