Intellij IDEA quick implementation of Docker image deployment method steps

Intellij IDEA quick implementation of Docker image deployment method steps

1. Docker enables remote access

[root@izwz9eftauv7x69f5jvi96z docker]# vim /lib/systemd/system/docker.service
#Modify the ExecStart line ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock 

#Reload the configuration file [root@izwz9eftauv7x69f5jvi96z docker]# systemctl daemon-reload    
#Restart service [root@izwz9eftauv7x69f5jvi96z docker]# systemctl restart docker.service 
#Check if the port is open [root@izwz9eftauv7x69f5jvi96z docker]# netstat -nlpt
#Directly curl to see if it works [root@izwz9eftauv7x69f5jvi96z docker]# curl http://127.0.0.1:2375/info

2. Install Docker plugin in Intellij IDEA

Open Idea, go to File->Settings->Plugins->Install JetBrains plugin to enter the plugin installation interface, enter docker in the search box, you can see Docker integration, click the Install button on the right to install it. Restart Idea after installation.

After restarting, configure docker and connect to the remote docker service. Open the configuration interface from File->Settings->Build,Execution,Deployment->Docker.

3. Spring boot service Docker deployment

3.1 Create a new Spring boot project and write a test interface

3.2 Modify the pom file, add properties, and add plugin

<properties>
        <java.version>1.8</java.version>
        <docker.image.prefix>bozai</docker.image.prefix>
    </properties>
 
 
    <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>
                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                    <dockerDirectory></dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
        </plugins>
    </build>

3.3 Configure the Dockerfile file: Create a new Dockerfile file in the project root directory.

The content is as follows:

FROM java:8
VOLUME /tmp
COPY target/demo-0.0.1-SNAPSHOT.jar demo.jar
RUN bash -c "touch /demo.jar"
EXPOSE 8080
ENTRYPOINT ["java","-jar","demo.jar"]

4. Create a Docker image

Package the project and execute the mvn clean package command in the idea Terminal to compile and package it. After packaging, a jar package will be generated in the target directory. After generating the jar package, you can start the service locally for testing. After testing, configure the Docker image creation command. Enter the configuration interface from Run->Edit Configrations.

Click Docker, then click the + sign, add a docker command, enter Name, select Server, select the Dockerfile file, enter the image tag, and complete the configuration.

Once completed, execute this command:

After successful execution, you can see this image on the remote docker:

Execute docker ps to see that the image has produced a container and started running:

Open the browser and access the test:

refer to:

https://my.oschina.net/wuweixiang/blog/2874064

https://blog.csdn.net/sealir/article/details/81200662

docker-maven-plugin plugin: https://blog.csdn.net/weixin_44424668/article/details/104062822

This is the end of this article about the steps to quickly implement Docker image deployment in Intellij IDEA. For more relevant IDEA Docker image 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:
  • Detailed explanation of the latest IDEA process of quickly deploying and running Docker images
  • How to configure docker in IDEA2021.2 to image the springboot project and release it with one click
  • idea combines docker to realize image packaging and one-click deployment

<<:  Detailed explanation of sample code for the improvement and changes brought by CSS variables to JS interactive component development

>>:  CSS style control to achieve IE submission form record history click return information is still there

Recommend

Implementation of Node connection to MySQL query transaction processing

Table of contents Enter the topic mysql add, dele...

Nginx reverse proxy configuration to remove prefix case tutorial

When using nginx as a reverse proxy, you can simp...

Detailed example of using if statement in mysql stored procedure

This article uses an example to illustrate the us...

Vue.js handles Icon icons through components

Icon icon processing solution The goal of this re...

Let the web page redirect to other pages after opening for a few seconds

Just add the following code to achieve it. Method ...

How to install MySQL 5.7.28 binary mode under CentOS 7.4

Linux system version: CentOS7.4 MySQL version: 5....

The difference between VOLUME and docker -v in Dockerfile

There are obvious differences between volume moun...

Example of JSON output in HTML format (test interface)

To display the JSON data in a beautiful indented ...

9 great JavaScript framework scripts for drawing charts on the web

9 great JavaScript framework scripts for drawing ...

Detailed explanation of the basic implementation principle of MySQL DISTINCT

Preface DISTINCT is actually very similar to the ...

HTML input file control limits the type of uploaded files

Add an input file HTML control to the web page: &...

How to use JS code compiler Monaco

Preface My needs are syntax highlighting, functio...

Summary of things to pay attention to in the footer of a web page

Lots of links You’ve no doubt seen a lot of sites ...