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

A bug fix for Tomcat's automatic shutdown

Preface Recently, a Java EE web project that has ...

Pure CSS to achieve input box placeholder animation and input verification

For more exciting content, please visit https://g...

React tsx generates random verification code

React tsx generates a random verification code fo...

How to deploy Spring Boot using Docker

The development of Docker technology provides a m...

How to use Docker to limit container resources

Problem Peeping In the server, assuming that the ...

Analyzing the node event loop and message queue

Table of contents What is async? Why do we need a...

How to use jsx syntax correctly in vue

Table of contents Preface Virtual DOM What is Vir...

Detailed explanation of nginx optimization in high concurrency scenarios

In daily operation and maintenance work, nginx se...

How to make a website look taller and more designed

“How to make a website look high-end? Or more des...

Detailed explanation of Bind mounts for Docker data storage

Before reading this article, I hope you have a pr...

How to implement responsiveness in Vue source code learning

Table of contents Preface 1. Key Elements of a Re...