The whole process of IDEA integrating docker to deploy springboot project

The whole process of IDEA integrating docker to deploy springboot project

1. IDEA downloads the docker plug-in

I won’t go into details here, just install it like other plugins

2. Cloud Server Docker

Note: My server uses centOS 7

2.1 Docker installation

https://www.jb51.net/article/213611.htm

2.2 Stop Docker Service

To prevent errors when restarting the Docker service, it is best to stop the Docker service first and then modify the configuration file.

Before stopping Docker, you must stop the running container first, otherwise errors may occur when starting the container later.

Stop the running container:

docker stop [container_id]

Then stop the docker service

systemctl stop docker

2.3 Docker configuration file modification

In order to use HTTP to connect IDEA to the docker on the server, you need to modify the docker configuration file as follows:

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

Modify the Execstart line and replace it with the following content to open port 2375 for HTTP remote connections:

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

2.4 Refresh the configuration file

The command is as follows:

systemctl daemon-reload

To test whether the configuration file is effective, enter the following command on the server. If the JSON string content appears, the file is effective.

curl http://127.0.0.1:2375/version

2.5 Start the Docker service

The command is as follows:

systemctl restart docker

2.6 Add port 2375 to the firewall

The command is as follows:

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

Restart the firewall:

firewall-cmd --reload

2.7 Alibaba Cloud adds security group rules

Here, please note that you need to enter the security group on the instance page, then configure the rules and open port 2375.

2.8 Testing remote HTTP connection

Enter http://127.0.0.1:2375/version in the local browser. Similarly, if a JSON string appears, an HTTP connection can be made.

At this point, you can use IDEA to integrate dokcer.

3. Maven project packaging

3.1 Packaging plugins

Add the springboot packaging plug-in to the pom file

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

3.2 Packaging of resource files and their location after packaging

In addition to packaging Java source files, you also need to package resource files, such as XML/YML/Properties/HTML files. But pay attention to the location where the HTML file is packaged. It should be placed in the META-INF/resources directory. Otherwise, the HTML page cannot be accessed after starting the jar package.

<resources>
    <resource>
        <directory>src/main/java</directory>
        <!--Here I put the mapper file in the java directory so I need to declare the compilation location-->
        <includes>
            <include>**/*.xml</include>
        </includes>
        <filtering>true</filtering>
    </resource>
    <resource>
        <!--Declare the compile location of the yml configuration file-->
        <directory>src/main/resources</directory>
    </resource>
    <resource>
        <!--Declare the HTML file compilation location and put the compiled file into the specified location-->
        <directory>src/main/webapp</directory>
        <targetPath>META-INF/resources</targetPath>
    </resource>
</resources>

3.3 Docker plugin

There are two things to note. First, there needs to be a prefix in front of the Docker image name, which is composed of [prefix]:[image name]:[version number]. Second, uppercase letters must not be included when specifying the image name.

Both name and version are used in project information

<groupId>org.team</groupId>
<artifactId>coolmeeting</artifactId>
<version>1.0-SNAPSHOT</version>
<name>coolmeeting</name>
<description>docker start meetingMS</description>

<properties>
    <java.version>1.8</java.version>
    <docker.image.prefix>team</docker.image.prefix>
</properties>


<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <!-- tag::plugin[] -->
    <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>1.0.0</version>
        <configuration>
            <dockerHost>http://127.0.0.1:2375</dockerHost>
            <!--Image name cannot contain uppercase letters-->
            <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
            <!--Dockerfile location-->
            <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
            <resources>
                <resource>
                    <targetPath>/</targetPath>
                    <!--target location-->
                    <directory>${project.build.directory}</directory>
                    <!--Put the jar package and Dockerfile in the same directory-->
                    <include>${project.build.finalName}.jar</include>
                </resource>
            </resources>
        </configuration>
    </plugin>
    <!-- end::plugin[] -->

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <skipTests>true</skipTests>
        </configuration>
    </plugin>
</plugins>

The Dockerfile file is as follows. Note that D should be capitalized when creating the file. /meetingMS.jar is an alias for easy writing.

FROM java:8
VOLUME /tmp
ADD coolmeeting-1.0-SNAPSHOT.jar /meetingMS.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/meetingMS.jar"]

3.4 clean, install and docker build

First use Maven to clean and install, then use the Maven plugin docker to build

insert image description here

The packaged file directory:

insert image description here

Start the container

insert image description here

Set startup parameters

insert image description here

4. Pitfalls encountered

  • Image name problem (cannot contain uppercase letters)
  • Springboot configuration file application.yml cannot be packaged
  • The html page cannot be accessed after packaging

5. References

Springboot packaged as jar cannot access jsp or html, 404 error

About yml or properties files not being scanned

Specify the startup port when running the Jar package

stackover

IDEA integrates Docker to quickly deploy SpringBoot applications

IDEA integrates Docker for quick deployment

This is the end of this article about IDEA integrating docker to deploy springboot project. For more relevant IDEA integrating docker to deploy springboot project content, 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:
  • How to configure docker in IDEA2021.2 to image the springboot project and release it with one click
  • Detailed steps to deploy SpringBoot projects using Docker in Idea
  • 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

<<:  CSS tips for controlling animation playback and pause (very practical)

>>:  Three common ways to embed CSS in HTML documents

Recommend

Detailed steps for running springboot project in Linux Docker

Introduction: The configuration of Docker running...

An article to show you how to create and use Vue components

Table of contents 1. What is a component? 2. Crea...

How to build a new image based on an existing image in Docker

Building new images from existing images is done ...

HTML form submission method case study

To summarize the form submission method: 1. Use t...

HTML&CSS&JS compatibility tree (IE, Firefox, Chrome)

What is a tree in web design? Simply put, clicking...

express project file directory description and detailed function description

app.js: startup file, or entry file package.json:...

Introduction to Nginx log management

Nginx log description Through access logs, you ca...

PyTorch development environment installation tutorial under Windows

Anaconda Installation Anaconda is a software pack...

How to change the host name in Linux

1. View the current host name [root@fangjian ~]# ...

How to deploy code-server using docker

Pull the image # docker pull codercom/code-server...

Native JS to achieve cool paging effect

This article uses an example to share with you a ...

CSS implements the web component function of sliding the message panel

Hello everyone, I wonder if you have the same con...

Self-study of MySql built-in functions knowledge points summary

String functions Check the ascii code value of th...