idea combines docker to realize image packaging and one-click deployment

idea combines docker to realize image packaging and one-click deployment

1. Install Docker on the server

yum install docker

Modify the configuration file and open port 2375

[root@microservice ~]# vim /usr/lib/systemd/system/docker.service

Add -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock after ExecStart=/usr/bin/dockerd-current \
Reload the configuration file and start:

systemctl daemon-reload
systemctl start docker

Appendix: Docker operation related commands

The systemctl command is a system service manager command, which is a combination of the service and chkconfig commands.
Start Docker: systemctl start docker
Stop Docker: systemctl stop docker
Restart Docker: systemctl restart docker
Check the docker status: systemctl status docker
Start at boot: systemctl enable docker

2. Idea installation docker support plug-in and configuration

1.idea downloads docker support plug-in: Docker integration

(Shortcut key Crtl+shift+A, search for Docker integration, then enable it, restart idea to take effect)

2. IDEA Docker plugin configuration

File–>Settings–>Build,Execution,Deployment–>Docker–>Configure as follows:

tcp://server ip address:2375

Note: As long as the following prompts Connection successfl, it means the connection is successful;

3. Configure the pom file:

<build>
  <finalName>${project.artifactId}</finalName>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <configuration>
        <fork>true</fork>
      </configuration>
    </plugin>
    <!-- Skipping unit tests -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <skipTests>true</skipTests>
      </configuration>
    </plugin>
    <!--Use the docker-maven-plugin plugin-->
    <plugin>
      <groupId>com.spotify</groupId>
      <artifactId>docker-maven-plugin</artifactId>
      <version>1.0.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 generated image name-->
        <imageName>fred/${project.artifactId}</imageName>
        <!--Specify tags-->
        <imageTags>
          <imageTag>latest</imageTag>
        </imageTags>
        <!-- Specify the Dockerfile path -->
        <dockerDirectory>src/main/docker</dockerDirectory>
        <!--Specify the remote docker api address-->
        <dockerHost>http://server ip address: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>

Attached project directory structure:

4. Write Dockerfile in the root directory

# Dockerfile
# Based on the image FROM openjdk:8-jdk-alpine
 
VOLUME /opt/tmp
 
ADD sg-business.jar app.jar
 
# -Djava.security.egd=file:/dev/./urandom can solve the problem that tomcat may start slowly# For details, please see: https://www.cnblogs.com/mightyvincent/p/7685310.html
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
 
# External port EXPOSE 8081

5. Click on the Maven package to build

Build a successful message

6. Click on the docker at the bottom to go to the docker interface. Double-click docker to connect to the server. Docker will display the docker image on the server. Find the image just generated (2 in the figure) and click Create Container.

7. Configure the docker container to expose the port and project interface port, then run to start the container

Finally, after setting up, start the container. After the startup is successful, go to Alibaba Cloud to check whether it is started successfully.

Reference blog address:

https://www.jianshu.com/p/186e9926600e

https://blog.lqdev.cn/2018/07/27/springboot/chapter-fourteen/

https://www.cnblogs.com/fangts/p/10299431.html

This is the end of this article about idea collection docker to achieve one-click deployment of image packaging. For more related idea collection docker to achieve one-click deployment of image packaging, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to package the project into docker through idea
  • A brief analysis of SpringBoot packaging and uploading to docker and implementing multi-instance deployment (IDEA version)
  • How to integrate Docker into IDEA to achieve packaging

<<:  How to pass W3C validation?

>>:  Box-shadow and drop-shadow to achieve irregular projection example code

Recommend

Search engine free collection of website entrances

1: Baidu website login entrance Website: http://ww...

Detailed explanation of Nginx timeout configuration

I recently used nginx in a project, and used Java...

Table related arrangement and Javascript operation table, tr, td

Table property settings that work well: Copy code ...

Discussion on horizontal and vertical centering of elements in HTML

When we design a page, we often need to center th...

MySQL InnoDB MRR Optimization Guide

Preface MRR is the abbreviation of Multi-Range Re...

In-depth understanding of Worker threads in Node.js

Table of contents Overview The history of CPU-bou...

Quickly master the use of Docker to build a development environment

As the platform continues to grow, the project...

Basic usage of @Font-face and how to make it compatible with all browsers

@Font-face basic introduction: @font-face is a CSS...

WeChat applet to obtain mobile phone number step record

Preface Recently, I encountered such a problem wh...

Web project development VUE mixing and inheritance principle

Table of contents Mixin Mixin Note (duplicate nam...

Centos 7 64-bit desktop version installation graphic tutorial

If you think the system is slow and want to chang...

Using NTP for Time Synchronization in Ubuntu

NTP is a TCP/IP protocol for synchronizing time o...

Tutorial on installing php5, uninstalling php, and installing php7 on centos

First, install PHP5 very simple yum install php T...