How to connect idea to docker to achieve one-click deployment

How to connect idea to docker to achieve one-click deployment

1. Modify the docker configuration file and open port 2375

[root@s162 docker]# vim /usr/lib/systemd/system/docker.service
#Find ExecStart, add # at the end and add -H tcp://0.0.0.0:2375 

[root@s162 docker]# systemctl daemon-reload
[root@s162 docker]# systemctl start docker

## Check whether port 2375 is enabled [root@s162 docker]# lsof -i:2375
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
dockerd 27021 root 5u IPv6 352598799 0t0 TCP *:2375 (LISTEN)

2. Idea installation and configuration of docker plug-in

2.1. Install the docker plugin from the idea-plugins market

slightly…

2.2. Configure Docker

insert image description here

3. Deploy the springboot project to the docker server

3.1. Writing docker/dockerfile

insert image description here

3.2. Maven adds docker-maven-plugin plug-in

 <plugin>
   <groupId>com.spotify</groupId>
   <artifactId>docker-maven-plugin</artifactId>
   <version>1.0.0</version>
   <configuration>
    <!--Specify the generated image name. If you do not specify a tag, the default will be to use the latest-->
    <imageName>jhs/${project.artifactId}:${project.version}</imageName>
    <!--Add additional specified tags, not required-->
    <!--
    <imageTags>
     <imageTag>${project.version}</imageTag>
    </imageTags>
    -->

    <!-- Specify the Dockerfile path: under the project root path -->
    <dockerDirectory>${project.basedir}/docker</dockerDirectory>
    <!--Specify the remote docker api address-->
    <dockerHost>http://192.168.129.162:2375</dockerHost>


    <!-- copy resources -->
    <resources>
     <resource>
      <targetPath>/</targetPath>
      <directory>${project.build.directory}</directory>
      <include>${project.build.finalName}.jar</include>
     </resource>
    </resources>


    <!--When docker build dockerfile: set variables when creating the image -->
    <buildArgs>
     <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
    </buildArgs>
   </configuration>
  </plugin>

3.3. docker:build

Use the command $ mvn clean package docker:build -Dmaven.test.skip=true to build the image and check whether the image is uploaded successfully on the docker server:

insert image description here

3.4 docker:tag

The docker command line format is : #docker tag <imageId or imageName> <nexus-hostname>:<repository-port>/<image>:<tag>

Plugin Configuration
<configuration> Additional configuration:

 <configuration>
	 <image>jhs/${project.artifactId}:${project.version}</image>
  <!-- docker tag -->
  <newName>192.168.129.160:5000/${project.artifactId}:${project.version}</newName>
</configuration>

Tag the image to prepare for the subsequent push: mvn clean docker:tag -Dmaven.test.skip=true -DskipDockerBuild

insert image description here

3.5 docker:push

Plugin Configuration
<configuration> Additional configuration:

<configuration>
	 <!-- docker push pushes to the remote image repository-->
  <!-- serverId: is the server information id configured in maven setting.xml-->
  <serverId>nexus-docker-registry</serverId>
  <registryUrl>192.168.129.160:5000</registryUrl>
  	
  	<!-- Push the new image with tag to Nexus-->
		<imageName>192.168.129.160:5000/${project.artifactId}</imageName>
</configuration>

Push the image tagged above to the private server nexus: mvn clean docker:push -Dmaven.test.skip=true -DskipDockerBuild -DskipDockerTag

insert image description here

3.6 Docker plugin parameters

  • -DskipDockerBuild to skip image build
  • -DskipDockerTag to skip image tag
  • -DskipDockerPush to skip image push
  • -DskipDocker to skip any Docker goals

3.7 Binding commands to Maven phases

<executions>
  <execution>
   <id>build-image</id>
   <phase>package</phase>
   <goals>
    <goal>build</goal>
   </goals>
  </execution>

  <execution>
   <id>tag-image</id>
   <phase>package</phase>
   <goals>
    <goal>tag</goal>
   </goals>
   <configuration>
    <image>jhs/${project.artifactId}:${project.version}</image>
    <newName>192.168.129.160:5000/${project.artifactId}:${project.version}</newName>
   </configuration>
  </execution>


  <execution>
   <id>push-image</id>
   <phase>deploy</phase>
   <goals>
    <goal>push</goal>
   </goals>
   <configuration>
    <!-- docker push pushes to the remote image repository-->
    <!-- serverId: is the server information id configured in maven setting.xml-->
    <serverId>nexus-docker-registry</serverId>
    <registryUrl>192.168.129.160:5000</registryUrl>
    <imageName>192.168.129.160:5000/${project.artifactId}</imageName>
   </configuration>
  </execution>

 </executions>

3.8 Best Practices

 <properties>
  <docker.host>http://192.168.129.162:2375</docker.host>
  <docker.registry.url>192.168.129.160:5000</docker.registry.url>
 </properties>
 
<build>
 <plugins>
 	<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>1.0.0</version>
  <configuration>
   <imageName>dic/${project.artifactId}:${project.version}</imageName>
   <!--Add additional specified tags (multiple tags can be configured), if not specified, it will be latest-->
   <!--
    <imageTags>
     <imageTag>${project.version}</imageTag>
    </imageTags>
    -->


   <!-- Specify the Dockerfile path: under the project root path -->
   <dockerDirectory>${project.basedir}/docker</dockerDirectory>
   <!--Specify the remote docker api address-->
   <dockerHost>${docker.host}</dockerHost>


   <!-- copy resources -->
   <resources>
    <resource>
     <targetPath>/</targetPath>
     <directory>${project.build.directory}</directory>
     <include>${project.build.finalName}.jar</include>
    </resource>
   </resources>


   <!--When docker build dockerfile: set variables when creating the image -->
   <buildArgs>
    <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
   </buildArgs>
  </configuration>

  <executions>
   <execution>
    <id>build-image</id>
    <phase>package</phase>
    <goals>
     <goal>build</goal>
    </goals>
   </execution>

   <execution>
    <id>tag-image</id>
    <phase>package</phase>
    <goals>
     <goal>tag</goal>
    </goals>
    <configuration>
     <image>dic/${project.artifactId}:${project.version}</image>
     <newName>${docker.registry.url}/${project.artifactId}:${project.version}</newName>
    </configuration>
   </execution>


   <execution>
    <id>push-image</id>
    <phase>deploy</phase>
    <goals>
     <goal>push</goal>
    </goals>
    <configuration>
     <!-- docker push pushes to the remote image repository-->
     <!-- serverId: is the server information id configured in maven setting.xml-->
     <serverId>nexus-docker-registry</serverId>
     <registryUrl>${docker.registry.url}</registryUrl>
     <imageName>${docker.registry.url}/${project.artifactId}</imageName>
    </configuration>
   </execution>

  </executions>
 </plugin>
 </plugins>
 </build>

4. Detailed steps for installing Harbor, a private Docker repository (supplement)

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

This is the end of this article about idea connecting docker to achieve one-click deployment. For more related idea connecting docker to achieve one-click deployment, 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 deploy stand-alone Pulsar and clustered Redis using Docker (development artifact)
  • Implementation of deploying war package project using Docker
  • Example of how to deploy MySQL 8.0 using Docker
  • Best Practices for Deploying ELK7.3.0 Log Collection Service with Docker
  • Detailed process of installing and deploying onlyoffice in docker

<<:  Detailed explanation of MySQL alter ignore syntax

>>:  Element Table table component multi-field (multi-column) sorting method

Recommend

How to deal with time zone issues in Docker

background When I was using Docker these two days...

Detailed explanation of the use of ElementUI in Vue

Login + sessionStorage Effect display After a suc...

Design Tips: We think you will like it

<br />Looking at this title, you may find it...

Web Design Tutorial (2): On Imitation and Plagiarism

<br />In the previous article, I introduced ...

mysql group by grouping multiple fields

In daily development tasks, we often use MYSQL...

MySQL 8.0.12 decompression version installation tutorial personal test!

Mysql8.0.12 decompression version installation me...

15 JavaScript functions worth collecting

Table of contents 1. Reverse the numbers 2. Get t...

Detailed explanation of the difference between $router and $route in Vue

We usually use routing in vue projects, and vue-r...

Detailed explanation of Nginx reverse proxy example

1. Reverse proxy example 1 1. Achieve the effect ...

Tutorial on installing MySQL 5.7.18 using RPM package

system: CentOS 7 RPM packages: mysql-community-cl...

MySQL uses frm files and ibd files to restore table data

Table of contents Introduction to frm files and i...

Detailed explanation of JavaScript BOM composition and common events

Table of contents 1. BOM 2. Composition of BOM 2....