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

The method of deploying spring-boot maven applications using Docker

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

Share

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

This article introduces the deployment of spring-boot maven applications using Docker and shares them with you. The details are as follows:

The deployment process is divided into the following steps:

Create a simple spring-boot application package run application containerization application add docker support to create docker image run docker container view running container startup / shutdown / restart / delete docker container

1. Create a simple spring-boot application

In IntelliJ IDEA, File- > New- > Project:

Then click Next- > Finish.

two。 Package and run the application

Add dependencies to pom.xml:

Org.springframework.boot spring-boot-starter-web

Add a controller:

Controllerpublic class HelloWorld {@ GetMapping ("/ hello") public void helloworld (HttpServletResponse response) throws IOException {response.getWriter () .write ("Hello Spring-boot");}}

Run the project, visit: http://localhost:8080/hello, if present: Hello Spring-boot step 2 completed.

3. Containerized application

Create a Dockerfile file in the project directory: src/main/docker/Dockerfile (no suffix), as follows:

FROM frolvlad/alpine-oraclejdk8:slimVOLUME / tmpADD demo-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"]

Where demo-0.0.1-SNAPSHOT.jar is the file name in the packaged / target/ of the project

4. Add docker support to pom files

Ramer com.spotify docker-maven-plugin 0.4.11 ${docker.image.prefix} / ${project.artifactId} src/main/docker / ${project.build.directory} ${project.build.finalName} .jar

5. Create a docker image

Cmd goes to the current directory:

Cd Z:/Desktop/springboot-demo

Package and create an image:

Mvn package-Dmaven.test.skip=true docker:build

Note: please make sure that maven has been added to path; and that docker is installed, if not, visit: https://www.docker.com/community-edition#/download to download the appropriate version.

6. Run the docker container

# # it's best to add-- name parameter docker run-- name=springboot-docker-demo-p 808080 name=springboot-docker-demo 8080-t ramer/demo

Visit from the browser: http://localhost:8080/hello

7. View running containers

Cmd: docker ps

8. Start / shut down / restart / delete the docker container

Cmd: docker start/stop/restart/rm CONTAINER_ID/NAME

Where:

CONTAINER_ID: container id, which can be viewed by executing docker ps

NAME: is the name of the container, which is the name after docker run-name

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

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