Detailed steps to deploy SpringBoot projects using Docker in Idea

Detailed steps to deploy SpringBoot projects using Docker in Idea

Preface

Project requirements:

Install the Docker plugin in Dockeridea and configure Docker to create a Dockerfile for a SpringBoot project

1. Download, install, and configure Docker

Download address: Download Docker from the official website

Install

Just keep going to the next step

Configuration path: Settings-General Check Expose daemon on tcp://localhost:2375 without TLS

insert image description here

Set up a mirror to increase the speed of downloading the mirror https://xaiqlt1z.mirror.aliyuncs.com

insert image description here

Test whether the installation is successful

C:\Users\msi>docker -v
Docker version 19.03.12, build 48a66213fe

C:\Users\msi>docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  (amd64)
 3. The Docker daemon creates a new container from that image which runs the
  executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
  to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

2. Idea Install Docker plugin

1. Install the Docker plug-in in idea: file--Plugins--Marketplace Search Docker Installation

insert image description here

2. Configure Docker service

file – Search for docker – Select Docker – Add a Docker on the right
Connection successful is displayed, indicating that the Docker connection is successful

insert image description here

3. Create a SpringBoot project, modify the pom.xmlspringMVC project, and access localhost:8080/hello to display the hello string

@RequestMapping("/hello")
  @ResponseBody
  public String hello () {
    return "hello";
  }

1. Configure the pom.xml file

<build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
          <execution>
            <id>build-image</id>
            <phase>package</phase>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <imageName>${project.artifactId}</imageName>
          <imageTags>
            <imageTag>latest</imageTag>
          </imageTags>
          <dockerDirectory>${project.basedir}</dockerDirectory>
          <dockerHost>http://localhost:2375</dockerHost>
          <resources>
            <resource>
              <targetPath>/</targetPath>
              <directory>${project.build.directory}</directory>
              <include>${project.build.finalName}</include>
            </resource>
          </resources>
        </configuration>
      </plugin>
    </plugins>
  </build>

2. Create a Docker file

Create a docker folder under the main folder and create a Dockerfile file in it. xxxxx.jar is copied in after being packaged using Maven.

insert image description here

Dockerfile file content:

# From java image, version : 8
FROM java:8

# Mount the app directory VOLUME /app

# COPY or ADD to image
COPY demo-0.0.1-SNAPSHOT.jar app.jar

RUN bash -c "touch /app.jar"
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

Maven packages and copies the jar package in its target directory into the docker directory.

Configure Dockerfile configuration

insert image description here

run

insert image description here

Run successfully

insert image description here

test

Use docker to check whether the container is started:

insert image description here

Test whether the project is started:

insert image description here

Summarize

I learned about Docker containers today. I learned the basic commands, but I still don’t understand how to use them. Take this opportunity to spend time learning. At present, I just know how to use it, and I will add a detailed description of the steps later.

This is the end of this article about using Docker to deploy SpringBoot projects in Idea. For more information about Docker deployment of SpringBoot projects, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • The whole process of IDEA integrating docker to deploy springboot project
  • How to configure docker in IDEA2021.2 to image the springboot project and release it with one click
  • Detailed tutorial on how to publish springboot projects through docker plug-in in IDEA
  • Deploy the springboot project to docker based on idea
  • Detailed explanation of the process of deploying SpringBoot project through Docker plug-in in IDEA

<<:  Typescript+react to achieve simple drag and drop effects on mobile and PC

>>:  Summary of several situations in which MySQL indexes fail

Recommend

Linux system MySQL8.0.19 quick installation and configuration tutorial diagram

Table of contents 1. Environment Introduction 2. ...

4 Scanning Tools for the Linux Desktop

While the paperless world has not yet emerged, mo...

Analysis of Mysql transaction characteristics and level principles

1. What is a transaction? A database transaction ...

MySQL quickly inserts 100 million test data

Table of contents 1. Create a table 1.1 Create te...

A brief discussion on JavaScript scope

Table of contents 1. Scope 1. Global scope 2. Loc...

JavaScript implementation of magnifying glass details

Table of contents 1. Rendering 2. Implementation ...

Compatibility with the inline-block property

<br />A year ago, there were no articles abo...

How to optimize the slow Like fuzzy query in MySQL

Table of contents 1. Introduction: 2. The first i...

The difference between JS pre-parsing and variable promotion in web interview

Table of contents What is pre-analysis? The diffe...

MySQL 5.7.21 installation and configuration method graphic tutorial (window)

Install mysql5.7.21 in the window environment. Th...

Common causes and solutions for slow MySQL SQL statements

1. Slow query due to lack of index or invalid ind...

Implementation of Vue large file upload and breakpoint resumable upload

Table of contents 2 solutions for file upload Bas...

MySQL character types are case sensitive

By default, MySQL character types are not case-se...

Vue integrates Tencent Map to implement API (with DEMO)

Table of contents Writing Background Project Desc...