IDEA configuration process of Docker

IDEA configuration process of Docker

IDEA is the most commonly used development tool for Java, and Docker is the most popular deployment container.

1. Configure Docker remote connection port

vi /usr/lib/systemd/system/docker.service

Find ExecStart and add -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock at the end

insert image description here

Restart Docker

 systemctl daemon-reload
 systemctl start docker

Open port 2375

firewall-cmd --zone=public --add-port=2375/tcp --permanent

2. Install Docker plugin in IDEA

1. File->Settings->Plugins search for docker integration

insert image description here

Restart IDEA after successful installation

3. Create a Springboot project and configure the connection to the remote docker pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.2</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.docker</groupId>
  <artifactId>idea-docker-demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>idea-docker-demo</name>
  <description>Demo project for Spring Boot</description>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <docker.image.prefix>com.docker</docker.image.prefix>
    <java.version>1.8</java.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <!-- Lombok -->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>1.0.0</version>
        <configuration>
          <dockerDirectory>src/main/docker</dockerDirectory>
          <resources>
            <resource>
              <targetPath>/</targetPath>
              <directory>${project.build.directory}</directory>
              <include>${project.build.finalName}.jar</include>
            </resource>
          </resources>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <configuration>
              <tasks>
                <copy todir="src/main/docker"
                   file="target/${project.artifactId}-${project.version}.${project.packaging}"></copy>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

</project>

application.properties

server.port=8887

logging.config=classpath:logback.xml
logging.path=/home/docker_demo/app/logs/

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="true" scanPeriod="1 seconds">

  <contextName>logback</contextName>
  <property name="log.path" value="/home/docker_demo/app/logs/docker_demo.log"/>

  <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${log.path}</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>
    </rollingPolicy>
    <encoder>
      <pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n
      </pattern>
    </encoder>
  </appender>

  <root level="info">
    <appender-ref ref="console"/>
    <appender-ref ref="file"/>
  </root>

</configuration>

Configure docker remote address

insert image description here

Create a Dockerfile file under the project

insert image description here

Dockerfile content:

FROM openjdk:8-jdk-alpine
ADD *.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

Add docker configuration

insert image description here
insert image description here

insert image description here

Command Explanation
Image tag: Specify the image name and tag. The image name is docker-demo and the tag is 1.1.
Bind ports: Bind host ports to container internal ports. The format is [host port]:[container internal port]
Bind mounts: Mount the host directory to the container's internal directory. The format is [host directory]:[container internal directory]. This springboot project will print the log in the container
/home/docker_demo/app/logs/ directory. After mounting the host directory to the directory inside the container, the logs will be persisted in the host directory outside the container.

3. Project packaging and deployment to docker

insert image description here
insert image description here

Project launch successful

insert image description here

You can directly access the interface and view the log files

insert image description here

Summary: It is simple and convenient to deploy springboot projects to docker through idea!

This is the end of this article about the process of configuring Docker in IDEA. For more relevant content about configuring Docker in IDEA, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • The latest idea2021 latest activation super detailed tutorial
  • Solve the problem of IDEA target folder getting bigger and bigger
  • About Intellij idea error: Error: java does not support release version 5
  • Permanently solve the problem of Intellij idea reporting error: Error: java does not support release version 5
  • IntelliJ IDEA tutorial on creating a common Java project and creating and running Java files
  • Solve the IDEA Gradle build error ''Cause: zip END header not found''
  • Solve the problem that IDEA takes up too much space on the C drive

<<:  202 Free High Quality XHTML Templates (1)

>>:  How to install MySQL for beginners (proven effective)

Recommend

Nginx source code compilation and installation process record

The installation of the rpm package is relatively...

Website User Experience Design (UE)

I just saw a post titled "Flow Theory and Des...

JS implements a stopwatch timer

This article example shares the specific code of ...

XHTML Getting Started Tutorial: XHTML Web Page Image Application

<br />Adding pictures reasonably can make a ...

SQL serial number acquisition code example

This article mainly introduces the sql serial num...

A brief discussion on several advantages of Vue3

Table of contents 1. Source code 1.1 Monorepo 1.2...

HTML form tag usage learning tutorial

Forms in HTML can be used to collect various type...

Node.js sends emails based on STMP protocol and EWS protocol

Table of contents 1 Node.js method of sending ema...

Nginx anti-crawler strategy to prevent UA from crawling websites

Added anti-crawler policy file: vim /usr/www/serv...

How to use port 80 in Tomcat under Linux system

Application Scenario In many cases, we install so...