IDEA uses Docker plug-in techniques

​​​​​​

Directory

1 docker to turn on remote and access

2 Connect docker

3 Retrieval of Mirrors

4. Create containers and run them

5 springboot project docker deployment

Preface

Previous articles mostly described docker mirroring pull-out, container creation, etc., which required a lot of commands to be remembered and quite skilled to deploy a project using docker. It would take a lot of time to deploy remotely using docker plug-in in idea. If you deploy remotely using docker plug-in, you can deploy remotely without typing commands. Here's an overview of ideaThe magic of docker plugins.

Prepare win10 to communicate with the local virtual machine without closing the firewall

Reference Documents win10 communicates with local virtual machines without closing the firewall _chenjin_csdn's blog-CSDN blog

1. Turn on docker remote access

The main point here is how to open docker remote access

First we need to configure docker's mirror accelerator (otherwise, pull image will be slow). Mirror acceleration We use Ali mirror, or NetEase or ustc

{"registry-mirrors": ["ali address", ""http://hub-mirror.c.163.com""https://docker.mirrors.ustc.edu.cn"]}

The preconditions are set, and then the docker transport city visit is officially configured to open.
Start by editing the docker's host file/lib/systemd/system/docker.
 

vi /lib/systemd/system/docker.service

Modify the line starting with ExecStart (if the system is centos 7):

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

If it is below centos7, change ExecStart to:

ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375

Save the file after modification and notify the docker service of the modification

systemctl daemon-reload

Restart docker service

service docker restart

Test to see if you can connect to docker api

curl http://localhost:2375/version
 

2. Connect docker

Download docker plugins

Click on idea's settings option (file --> setting -> docker) to create a new connection

 

Open the project and click services connection in the lower left corner

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

   

3. Retrieval of Mirror

idea pulls the mirror visually

All we need to do is fill in the repository with the name of the image we want to pull

Remove Mirror

4. Create containers and run them

Fill in container name and mapping port

View Log Run Successfully

5. springboot project docker deployment

In general, docker deploying springboot projects requires manual configuration of the Dockerfile itself and uploading the generated jar packages to the server along with the Dockerfile files, which is particularly cumbersome. It is very convenient to deploy springboot projects at one click using idea docker plug-in.

The springboot project introduces docker building tools

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

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


            <!--Use docker-maven-plugin Plug-in unit-->
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.0.0</version>
                <!--Bind the plug-in to a phase implement-->
                <executions>
                    <execution>
                        <id>build-image</id>
                        <!--Users only need to execute mvn package ,Will execute automatically mvn docker:build-->
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <!--Specify the generated mirror name,Here's our author name+Project Name-->
                    <imageName>cainiao/${project.artifactId}</imageName>

                    <!--Specify label Specify here the mirror version, our default version is latest-->
                    <imageTags>
                        <imageTag>latest</imageTag>
                    </imageTags>

                    <!--Specify Base Mirror jdk1.8-->
                    <baseImage>java</baseImage>
                    <!--
                    Mirror Producer Personal Information
                    <maintainer>bruceliu@email.com</maintainer>
                    -->
                    <!--switch to ROOT Catalog-->
                    <workdir>/ROOT</workdir>

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

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

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

                    <!-- Here is the copy jar Package to docker Container Specified Directory Configuration -->
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <!--jar The path where the package is located  The corresponding configuration here target Catalog-->
                            <directory>${project.build.directory}</directory>
                            <!--Used to specify which files need to be copied to include jar Package, which corresponds to Dockerfile File name added in -->
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>

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

Next, click clean to clear all previously packaged files, then click package packaged files to complete the construction of the image and achieve one-click deployment.

 

Tags: Linux Docker Spring Boot IDEA

Posted on Mon, 13 Sep 2021 13:25:12 -0400 by ps2gamer