Get the App
SLTechnology News&Howtos  ›  Development  › 

How java deploys springboot to Docker remotely through Idea with one click

Shulou Source: shulou.com Published: 2022-06-02 12:20:57 10月25日 Update

This article mainly introduces how java deploys springboot to Docker remotely through Idea, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

I. preparation before development

1. For the installation of Docker, please refer to https://docs.docker.com/install/

two。 Configure docker remote connection port

Vi / usr/lib/systemd/system/docker.service

Find ExecStart and add-H tcp://0.0.0.0:2375 at the end, as shown in the following figure

3. Restart docker

Systemctl daemon-reloadsystemctl start docker

4. Open port

Firewall-cmd-zone=public-add-port=2375/tcp-permanent

5. Idea installs the plug-in and restarts

6. Connect to a remote docker

(1) Edit configuration

(2) enter remote docker address

(3) if the connection is successful, the remote docker container and image will be listed.

II. New projects

1. Create a springboot project

Project structure diagram

(1) configure pom file

4.0.0dockerkodemocom.demo1.0anthsSNAPOOTorg.springframework.bootspringklore bootspringkill starterflow parent2.0.2.RELEASEUTFFMY 8com.demo1.8org.springframework.bootspringmilebootspringripbootspringmilebootspringMaxic.com. SpotifydockerShaft plugin1.0.0srcspur antrun-pluginpackagerunorg.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-testtestlog4jlog4j1.2.17 the main big dockerspace ${project.build.directory} ${project.build.finalName} .jarmaven-docker

(2) create a docker directory under the src/main directory and create a Dockerfile file

FROM openjdk:8-jdk-alpineADD * .jar app.jarENTRYPOINT ["java", "- Djava.security.egd=file:/dev/./urandom", "- jar", "/ app.jar"]

(3) create an application.properties file in the resource directory

Logging.config=classpath:logback.xmllogging.path=/home/developer/app/logs/server.port=8990

(4) create DockerApplication file

@ SpringBootApplicationpublic class DockerApplication {public static void main (String [] args) {SpringApplication.run (DockerApplication.class, args);}}

(5) create DockerController file

@ RestControllerpublic class DockerController {static Log log = LogFactory.getLog (DockerController.class); @ RequestMapping ("/") public String index () {log.info ("Hello Docker!"); return "Hello Docker!";}}

(6) add configuration

Command interpretation

Image tag: specify the image name and tag, and the image name is docker-demo,tag: 1.1 Bind ports: bind the host port to the container internal port. Format is "Host Port": "Container Internal Port" Bind mounts: hang the host directory to the container internal directory. The format is [host directory]: [container internal directory]. The springboot project will print the log in the container / home/developer/app/logs/ directory. After mounting the host directory to the container's internal directory, the log will be persisted in the host directory outside the container.

(7) Maven packing

(8) run

First pull the basic image, then package the image, and deploy the image to a remote docker to run

Here we can see that the image name is docker-demo:1.1,docker and the container is docker-server.

(9) run successfully

(10) browser access

(11) Log viewing

Since then, the springboot project has been successfully deployed to docker through idea! It's hard to imagine how easy and convenient it is to deploy a Javaweb project!

Thank you for reading this article carefully. I hope the article "how java can remotely deploy springboot to Docker through Idea" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Tags: Directory container image host host port project file article configuration success name log run one click format reference unimaginable value interest Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information NVidia Docker OPPO Reno