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

ReactHooks batch update state and get route parameters example analysis

Table of contents 1. How to update in batches Con...

Install JDK1.8 in Linux environment

Table of contents 1. Installation Environment 2. ...

Some conclusions on developing mobile websites

The mobile version of the website should at least...

Vue implements chat interface

This article example shares the specific code of ...

React tips teach you how to get rid of hooks dependency troubles

A very common scenario in react projects: const [...

Summary of the differences and usage of plugins and components in Vue

The operating environment of this tutorial: Windo...

Summary of several common logs in MySQL

Preface: In the MySQL system, there are many diff...

Detailed explanation of HTML programming tags and document structure

The purpose of using HTML to mark up content is t...

How to set the style of ordered and unordered list items in CSS

In an unordered list ul>li, the symbol of an u...

Using Apache ab to perform http performance testing

Mac comes with Apache environment Open Terminal a...

Semantics: Is Html/Xhtml really standards-compliant?

<br />Original text: http://jorux.com/archiv...

Sample code for implementing image drawer effect with CSS3

As usual, let’s first post the picture effect: Th...

How to enable Swoole Loader extension on Linux system virtual host

Special note: Only the Swoole extension is instal...

mysql trigger creation and usage examples

Table of contents What is a trigger Create a trig...