IDEA uses the Docker plug-in (novice tutorial)

IDEA uses the Docker plug-in (novice tutorial)

illustrate

Previously, learning Docker, including image pulling, container creation and other operations, required manual typing of commands to implement. However, if you use the Docker plug-in in idea, you can operate Docker without typing commands. I have to say that the idea tool is really powerful! ! ! This article will be continuously updated and expanded

This article is only for recording learning tracks. If there is any infringement, please contact us to delete it.

Note: Generally, a server is used. As a test, a virtual machine + Ubuntu system is used here.

1. Enable Docker remote access

If you use the idea editor, you can use the docker plug-in to remotely use the docker on the server (virtual machine). It is simple, convenient and fast to use docker. More importantly, the plug-in can realize one-click deployment of the project. Of course, this also requires some simple configuration.
The default docker does not support remote access. You need to add some configuration to enable remote access to Docker.

#To modify the Docker service file, you need to switch to the root user vim /lib/systemd/system/docker.service
#Comment out the "ExecStart" line and add the following line ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375

insert image description here

Reload the configuration file

#Reload the configuration file systemctl daemon-reload
#Restart the service systemctl restart docker.service
#Check whether the configured port number (2375) is enabled (optional)
netstat -nlpt #If you can't find the netstat command, you can install this tool first. For details, please visit Baidu 

insert image description here

Note: If the above process fails, there is a way to do it.

First, make sure the port number is open, this is very important! ! ! , the default port number is 2375

Switch to root user, command: sudo su

Edit Docker related configuration:
Command: vim /lib/systemd/system/docker.service to enter the editing page

insert image description here

Find the line corresponding to ExecStart and add the code: -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock (Press the "i" key to enter the edit mode, and then you can add data)

insert image description here

To save and exit, press the "esc" key first, then enter the command: :wq and press Enter to save.

Restart the Docker service daemon: sudo systemctl daemon-reload
Restart the docker service: sudo systemctl restart docker

Check whether port number 2375 is open. If the following figure is displayed, it is successful.

insert image description here

2. Connect to Docker

Use the docker plug-in of idea to connect to docker. idea has downloaded the docker plug-in by default. If not, you need to download the docker plug-in in idea.

insert image description here

Click the setting option of idea (file --> setting -> docker) to create a new connection

insert image description here

insert image description here

After the connection is successful, you can use docker on the server (virtual machine)

insert image description here

3. Pulling the Image

Idea can pull images in a visual way without typing commands yourself

insert image description here

insert image description here

insert image description here

Sometimes the pull time will time out. You can configure the domestic image to obtain the Alibaba Cloud accelerator.

insert image description here

4. Creation and operation of containers

Create and run a docker container

insert image description here

insert image description here

After the creation is successful, you can see the newly created container, or you can use the docker command to view it on the server (virtual machine)

insert image description here

Restarting, stopping, and deleting containers

insert image description here

5. One-click deployment of springboot project in docker

To deploy a springboot project with traditional docker, you need to manually configure the Dockerfile file and upload the generated jar package to the server together with the Dockerfile file. The whole process is very troublesome. If you use the idea docker plug-in, you can deploy the springboot project with one click, which is simple and convenient.

First you need to introduce the docker build tool

    <build>
        <!-- Quote our project name-->
        <finalName>${project.artifactId}</finalName>

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


            <!--Use the docker-maven-plugin plugin-->
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.0.0</version>
                <!--Bind the plugin to a certain phase for execution-->
                <executions>
                    <execution>
                        <id>build-image</id>
                        <!--Users only need to execute mvn package, and mvn docker:build will be automatically executed-->
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <!--Specify the generated image name, here is our author name + project name-->
                    <imageName>cainiao/${project.artifactId}</imageName>

                    <!--Specify the tag here to specify the version of the image, our default version is latest-->
                    <imageTags>
                        <imageTag>latest</imageTag>
                    </imageTags>

                    <!--Specify the base image jdk1.8-->
                    <baseImage>java</baseImage>
                    <!--
                    Image producer's personal information <maintainer>[email protected]</maintainer>
                    -->
                    <!--Switch to the ROOT directory-->
                    <workdir>/ROOT</workdir>

                    <!-- Check our java version -->
                    <cmd>["java", "-version"]</cmd>

                    <!--${project.build.finalName}.jar is the name of the jar package generated after packaging-->
                    <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>

                    <!--Specify the remote docker api address-->
                    <dockerHost>http://192.168.29.133:2375</dockerHost>

                    <!-- Here is the configuration for copying the jar package to the specified directory of the docker container-->
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <!--The path where the jar package is located corresponds to the target directory -->
                            <directory>${project.build.directory}</directory>
                            <!--Used to specify the jar package that needs to be included in the file to be copied, which corresponds to the file name added in Dockerfile-->
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>

                </configuration>
            </plugin>
        </plugins>
    </build>

OK, then just click clean to clear all the previously packaged files, and then click package to complete the image building, which is a real one-click deployment.

insert image description here

insert image description here

Now the image is built successfully. Next, just create a container and run it.

insert image description here

insert image description here

Access via IP

insert image description here

At this point, the one-click construction and deployment of the springboot project is successful!

Possible errors:

"java.lang.NoClassDefFoundError:javax/activation/DataSource" (tomcat 9.0.12)"

I checked online and found this passage. See here for details.

insert image description here

I just remembered that this project was developed with jdk8 before, and now I use jdk11, so this problem will occur during the build. I think it should be caused by this problem . Although the build is successful and there are no problems with running and access, it is recommended to keep the jdk version consistent when developing and building docker.

This is the end of this article about using the Docker plug-in for IDEA (novice tutorial). For more relevant content about using Docker for IDEA, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • idea uses docker plug-in to achieve one-click automated deployment
  • How to use Docker plugin to remotely deploy projects to cloud servers in IDEA
  • Solve the problem of garbled logs after IDEA integrates Docker plug-in
  • Detailed tutorial on how to publish springboot projects through docker plug-in in IDEA
  • Detailed process of installing the docker plugin in IntelliJ IDEA (2018 version)

<<:  Summary of some common techniques in front-end development

>>:  Low-version Druid connection pool + MySQL driver 8.0 causes thread blocking and performance limitation

Recommend

Three ways to refresh iframe

Copy code The code is as follows: <iframe src=...

Summary of the differences between get and post requests in Vue

The operating environment of this tutorial: Windo...

Details of the order in which MySQL reads my.cnf

Table of contents The order in which MySQL reads ...

Examples of using Docker and Docker-Compose

Docker is an open source container engine that he...

A brief analysis of how MySQL implements transaction isolation

Table of contents 1. Introduction 2. RC and RR is...

Solution to secure-file-priv problem when exporting MySQL data

ERROR 1290 (HY000) : The MySQL server is running ...

Solution to elementui's el-popover style modification not taking effect

When using element-ui, there is a commonly used c...

Three methods to modify the hostname of Centos7

Method 1: hostnamectl modification Step 1 Check t...

Use Rem layout to achieve adaptive

I have written an article about mobile adaptation...

Solution to the garbled code problem in MySQL 5.x

MySQL is a commonly used open source database sof...

How to change password and set password complexity policy in Ubuntu

1. Change password 1. Modify the password of ordi...

The difference between ${param} and #{param} in MySQL

The parameter passed by ${param} will be treated ...

The use of MySQL triggers and what to pay attention to

Table of contents About Triggers Use of triggers ...

In-depth analysis of Nginx virtual host

Table of contents 1. Virtual Host 1.1 Virtual Hos...