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

CSS to achieve horizontal lines on both sides of the middle text

1. The vertical-align property achieves the follo...

Detailed tutorial on installing mysql8.0.22 on Alibaba Cloud centos7

1. Download the MySQL installation package First ...

Example code for implementing random roll caller in html

After this roll call device starts calling the ro...

Vue realizes the percentage bar effect

This article shares the specific code of Vue to r...

Methods and steps for Etcd distributed deployment based on Docker

1. Environmental Preparation 1.1 Basic Environmen...

Learn about CSS label display mode in one article

Tag type (display mode) HTML tags are generally d...

How to implement the @person function through Vue

This article uses vue, and adds mouse click event...

XHTML Getting Started Tutorial: XHTML Tags

Introduction to XHTML tags <br />Perhaps you...

A brief discussion on two methods to solve space-evenly compatibility issues

Since its launch in 2009, flex has been supported...

Use of MySQL truncate table statement

The Truncate table statement is used to delete/tr...