Detailed process of integrating docker with idea to quickly deploy springboot applications

Detailed process of integrating docker with idea to quickly deploy springboot applications

1. Introduction

I believe everyone is familiar with the term containerization. When we hear it, we may think of docker, k8s, jenkins, rancher, etc. So today I will talk about how idea uses docker to quickly deploy springboot applications.

2. Environment and Tools

  • Windows 10 (Development)
  • centos 7.6 (deployment)
  • idea
  • docker
  • xshell

3. Install Docker and configure remote connection

There are many steps to install Docker on the Internet, so let’s talk about them again here:

Update first

sudo yum update

Install the latest docker

yum install docker -y

After installation as shown in the figure

Start Docker

systemctl start docker

You can use docker images to view the image status. The following figure shows that the startup is successful (there is currently no image in it)

insert image description here

If it is as shown below, it means startup failed

insert image description here

Open docker remote connection and edit the docker.service file

vim /lib/systemd/system/docker.service

After opening, the content is as follows:

insert image description here

Add the following to the line with the green cursor:

# centos7 and above ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
# centos7 below ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375

Here I use other ports, such as 12377. After the change, the content is as shown below:

insert image description here

After saving, reload the configuration file and restart Docker:

systemctl daemon-reload 
systemctl restart docker

To check whether port 12377 is being listened, execute lsof -i:12377

insert image description here

If you are using a cloud server, you need to enable the 12377 firewall rule. If you use the default port 2375, it doesn't matter if it is only used in a virtual machine or intranet. If it is exposed to the public network, you will probably find that your CPU is full the next day and a large number of horse and mining programs are mounted. Students who have time can further configure the security configuration. You can search it here.

4. idea connects to remote docker

Install the docker plugin

insert image description here

After the configuration connection is installed, find the location in the setting as shown below

insert image description here

Configure your docker address on the TCP socket in the following format:
tcp://ip:12377 . After filling in the information, wait for a while and the connection test will be performed. If the connection is successful, it will be displayed as shown in the figure above. 5. Springboot project configuration docker pom configuration blogger's current project packaging method is jar package, the properties configuration in pom is as follows

<properties>
    <!--Set the prefix of the docker image in the properties node "springboot" -->
    <docker.image.prefix>springboot</docker.image.prefix>
</properties>

The build is configured as follows:

 <build>
        <finalName>docker-demo</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
            </plugin>
            <plugin>
                <!-- docker-maven plugin -->
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <dockerHost>http://ip:12377</dockerHost>
                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                    <dockerDirectory>src/main/docker</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
        </plugins>
    </build>

resources is to find the packaged jar, dockerDirectory is to find Dockerfile configured in the project, and imageName is the image name

Create a Dockerfile (note that the Dockerfile is not camel case)
The structure is shown in the figure below

insert image description here

Dockerfile file content:

FROM williamyeh/java8 # The source can be searched using docker search java8. VOLUME /tmp
ADD docker-demo.jar /app/docker-demo.jar
#COPY target/demo-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java", "-jar", "/app/docker-demo.jar"]

FROM : specifies the base image, must be the first command
VOLUME : used to specify a persistent directory
ADD : Add local files to the container. Tar files will be automatically decompressed (network compressed resources will not be decompressed). Network resources can be accessed, similar to wget
ENTRYPOINT : Configure the container to make it executable

You can search for other instructions by yourself

  • So far, the required configuration has been completed, and then start running
  • Find the Maven window on the right side of idea and execute clean

insert image description here

After clean is completed, execute package to package

insert image description here

Then execute docker:build as shown in the figure

insert image description here

In this process, a docker folder will be created in the target directory, and the Dockerfile file and the generated jar package will be copied. Then, according to the configuration in the Dockerfile, the base image will be pulled, the jar will be transferred to the specified location of the server, and then the image will be made. After BUILD SUCCESS, click Services at the bottom of idea

insert image description here

The window is as follows

insert image description here

Double-click Docker to connect. After the connection is successful, we can see the image and container running status:

insert image description here

Then you can right-click the springboot/**:latest image to create a container

insert image description here

The create option pops up to create the configuration

insert image description here

Configure the container name and run options, and finally click Run to run the container. In the Services window we can see the container's running log:

insert image description here

So far, the idea of ​​integrating docker to quickly deploy springboot applications has been completed. I will summarize the use of jenkins+k8s+docker later.

This is the end of this article about idea integration docker quick deployment of springboot application. For more related idea docker deployment springboot content, please search 123WORDPRESS.COM previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Implementation steps for Docker deployment of SpringBoot applications
  • Detailed process of SpringBoot integrating Docker
  • Introduction to Docker Quick Deployment of SpringBoot Project

<<:  MYSQL's 10 classic optimization cases and scenarios

>>:  Review of the best web design works in 2012 [Part 1]

Recommend

Detailed explanation of MySQL master-slave replication process

1. What is master-slave replication? The DDL and ...

Summary of shell's method for determining whether a variable is empty

How to determine whether a variable is empty in s...

HTML checkbox Click the description text to select/uncheck the state

In web development, since the checkbox is small an...

Creating a Secondary Menu Using JavaScript

This article example shares the specific code of ...

Summary of Linux date command knowledge points

Usage: date [options]... [+format] or: date [-u|-...

How to insert batch data into MySQL database under Node.js

In the project (nodejs), multiple data need to be...

Detailed explanation and extension of ref and reactive in Vue3

Table of contents 1. Ref and reactive 1. reactive...

Examples of correct use of maps in WeChat mini programs

Table of contents Preface 1. Preparation 2. Actua...

5 ways to achieve the diagonal header effect in the table

Everyone must be familiar with table. We often en...

How to implement insert if none and update if yes in MySql

summary In some scenarios, there may be such a re...

Detailed explanation of how to use Vue to load weather components

This article shares with you how to use Vue to lo...

Summary of horizontal scrolling website design

Horizontal scrolling isn’t appropriate in all situ...

How to use geoip to restrict regions in nginx

This blog is a work note environment: nginx versi...

Sublime Text - Recommended method for setting browser shortcut keys

It is common to view code effects in different br...

How to handle super large form examples with Vue+ElementUI

Recently, due to business adjustments in the comp...