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

Unity connects to MySQL and reads table data implementation code

The table is as follows: Code when Unity reads an...

Detailed explanation of MySQL startup options and system variables examples

Table of contents Boot Options Command Line Long ...

Detailed example of clearing tablespace fragmentation in MySQL

Detailed example of clearing tablespace fragmenta...

Grid systems in web design

Formation of the grid system In 1692, the newly c...

CSS and JS to achieve romantic meteor shower animation

1. Rendering 2. Source code HTML < body > &...

How to create, start, and stop a Docker container

1. A container is an independently running applic...

MySQL 8.0.16 Win10 zip version installation and configuration graphic tutorial

This article shares with you the installation and...

XHTML Web Page Tutorial

<br />This article is mainly to let beginner...

Ten Experiences in Presenting Chinese Web Content

<br /> Focusing on the three aspects of text...

Docker+nextcloud to build a personal cloud storage system

1. Docker installation and startup yum install ep...

Innodb system table space maintenance method

Environmental Description: There is a running MyS...

Two practical ways to enable proxy in React

Two ways to enable proxy React does not have enca...

CSS to achieve zoom in and out close button (example code)

This effect is most common on our browser page. L...