Detailed steps for IDEA to integrate docker to achieve remote deployment

Detailed steps for IDEA to integrate docker to achieve remote deployment

1. Enable remote access to the docker server

Log in to the remote server where docker is located, and use the command vim /usr/lib/systemd/system/docker.service to modify the configuration file. Please note that when making changes, please confirm that your account has the corresponding permissions.

The main operation is to find Comment out the line ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock and add a new line after it. Added -H tcp://0.0.0.0:2375 to open port 2375 and support remote connection to docker

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

After saving the configuration file, you need to reload the configuration and restart Docker. You can use the following command

systemctl daemon-reload
systemctl restart docker.service

2. Install the docker plugin in IDEA

Generally, newer IDEAs are bound to the docker plug-in. If it is not bound, search and install the docker plug-in in IDEA's Plugins. After installation, restart the system to take effect.

insert image description here

After restarting, you can Build, Execution, Depolyment ——> Docker path to find the Docker plug-in, and then add a new configuration to connect to the remote Docker

insert image description here

After the connection is successful, you can view the image and container of the remote Docker host in the IDEA plug-in panel, as well as the log of the container operation and other information.

insert image description here

3. Docker image build and upload

To build the locally packaged jar into a docker image, you need to add a build plugin configuration in the project pom file. The following is a packaging configuration of a SpringBoot project module. The key points are as follows:

Build a jar package named nathan-api . First, add spring-boot-maven-plugin plug-in and add a docker-maven-plugin plug-in to configure the key properties of the docker image. Note that this plugin will download the com.spotify.docker-maven-plugin jar package. If the download fails, try changing several versions. For a list of versions, refer to the Maven Central Repository.
 <build>
     <finalName>nathan-api</finalName>
     <plugins>
         <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
             <version>2.4.2</version>
             <executions>
                 <execution>
                     <goals>
                         <goal>repackage</goal>
                     </goals>
                 </execution>
             </executions>
         </plugin>

         <plugin>
             <groupId>com.spotify</groupId>
             <artifactId>docker-maven-plugin</artifactId>
             <version>1.1.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 docker file directory-->
                 <dockerDirectory>${project.basedir}/docker</dockerDirectory>
                 <!--Specify the generated image name-->
                 <imageName>${project.artifactId}</imageName>
                 <!--Specify tags-->
                 <imageTags>
                     <imageTag>latest</imageTag>
                 </imageTags>
                 <!--Specify the remote docker api address-->
                 <dockerHost>http://xxx.168.146.63: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>
                         <!-- The jar package that needs to be included, which corresponds to the file name added in Dockerfile-->
                         <include>${project.build.finalName}.jar</include>
                     </resource>
                 </resources>
             </configuration>
         </plugin>

     </plugins>
 </build>

In the previous step, the directory of the docker file was configured in the docker maven plugin, and docker folder in the root directory of the module was specified. Then create a Create a new file named Dockerfile at the same level as src. The content is as follows:

FROM java:8
VOLUME /tmp
# Copy the packaged jar to app.jar ADD nathan-api.jar app.jar
EXPOSE 20561
# The following is the jar package startup command configuration ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom","-Duser.timezone=GMT+8", "-jar", "app.jar"]

After the above configuration, the action of building the docker image has been bound to the maven package command, so you can execute the package

The author encountered the error ADD failed: file not found in build context or excluded by .dockerignore at this step. The main problem is that the source files that the ADD command in Dockerfile needs to copy are not found. When this error occurs, first check whether the file path configured in the Dockerfile is correct, and then check whether the actual packaged jar name is the same as the file name configured in Dockerfile . I checked the configuration and confirmed that there were no path and name errors. Finally, I cleaned and restarted IDEA several times and it worked again. Don't ask why, asking is metaphysics

insert image description here

After the docker image is built, right-click the image file and choose to create a container. The simplest step to create a new container is to name the container, then add the port mapping from the host to the container. After the creation is successful, the container will automatically run.

insert image description here

This is the end of this article about the detailed steps of IDEA integrating docker to achieve remote deployment. For more relevant IDEA remote deployment content, 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:
  • Steps for IDEA to integrate Docker to achieve remote deployment
  • Idea deploys remote Docker and configures the file
  • How to use Docker plugin to remotely deploy projects to cloud servers in IDEA
  • Detailed tutorial on how to connect to a remote server Docker to deploy a Spring Boot project in IDEA
  • Java remote one-click deployment of springboot to Docker through Idea
  • Implementation of IDEA remote management of docker images and container services

<<:  Detailed introduction and usage examples of map tag parameters

>>:  WeChat applet uniapp realizes the left swipe to delete effect (complete code)

Recommend

Adobe Brackets simple use graphic tutorial

Adobe Brackets is an open source, simple and powe...

Some points on using standard HTML codes in web page creation

The most common mistake made by many website desi...

CSS3 uses var() and calc() functions to achieve animation effects

Preview knowledge points. Animation Frames Backgr...

Introduction and tips for using the interactive visualization JS library gojs

Table of contents 1. Introduction to gojs 2. Gojs...

Introduction to new ECMAscript object features

Table of contents 1. Object properties 1.1 Attrib...

Implementation steps for installing RocketMQ in docker

Table of contents 1. Retrieve the image 2. Create...

How to change the domestic source of Ubuntu 20.04 apt

UPD 2020.2.26 Currently Ubuntu 20.04 LTS has not ...

Basic principles for compiling a website homepage

1. The organizational structure of the hypertext d...

UTF-8 and GB2312 web encoding

Recently, many students have asked me about web p...

How to read the regional information of IP using Nginx and GeoIP module

Install GeoIP on Linux yum install nginx-module-g...

CocosCreator learning modular script

Cocos Creator modular script Cocos Creator allows...

Javascript to achieve drumming effect

This article shares the specific code of Javascri...

How to configure the My.ini file when installing MySQL5.6.17 database

I recently used the MySql database when developin...

Detailed tutorial on installing ElasticSearch 6.x in docker

First, pull the image (or just create a container...

HTML 5 Reset Stylesheet

This CSS reset is modified based on Eric Meyers...