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 Enable or Disable Linux Services Using chkconfig and systemctl Commands

This is an important (and wonderful) topic for Li...

Three strategies for rewriting MySQL query statements

Table of contents Complex query and step-by-step ...

jQuery implements form validation

Use jQuery to implement form validation, for your...

How to build a standardized vmware image for kubernetes under rancher

When learning kubernetes, we need to practice in ...

mysql5.7.18 decompressed version to start mysql service

The decompressed version of mysql5.7.18 starts th...

Detailed explanation of the function and usage of DOCTYPE declaration

1. Browser rendering mode and doctype Some web pa...

Sample code for implementing PC resolution adaptation in Vue

Table of contents plan Install Dependencies Intro...

Detailed explanation of mysql filtering replication ideas

Table of contents mysql filtered replication Impl...

Interviewer asked how to achieve a fixed aspect ratio in CSS

You may not have had any relevant needs for this ...

How to optimize MySQL index function based on Explain keyword

EXPLAIN shows how MySQL uses indexes to process s...

Analysis of statement execution order of sql and MySQL

I encountered a problem today: Can I use the as a...

Summary of Kubernetes's application areas

Kubernetes is the leader in the container orchest...

Implementation of services in docker accessing host services

Table of contents 1. Scenario 2. Solution 3. Conc...