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

Use of MySQL triggers

Triggers can cause other SQL code to run before o...

How to Learn Algorithmic Complexity with JavaScript

Table of contents Overview What is Big O notation...

js handles account logout when closing the browser

Table of contents Classic approach question Furth...

A quick guide to MySQL indexes

The establishment of MySQL index is very importan...

What does mysql database do

MySQL is a relational database management system ...

Solution to mysql login warning problem

1. Introduction When we log in to MySQL, we often...

vue $set implements assignment of values ​​to array collection objects

Vue $set array collection object assignment In th...

Detailed explanation of CSS weight value (cascading) examples

•There are many selectors in CSS. What will happe...

Solve the problem of IDEA configuring tomcat startup error

The following two errors were encountered when co...

MySQL data compression performance comparison details

Table of contents 1. Test environment 1.1 Hardwar...

JavaScript to implement the function of changing avatar

This article shares the specific code of JavaScri...

Implementation of Vue package size optimization (from 1.72M to 94K)

1. Background I recently made a website, uidea, w...