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

mysql 5.7.18 winx64 password change

After MySQL 5.7.18 is successfully installed, sin...

Super detailed MySQL usage specification sharing

Recently, there have been many database-related o...

HTML reuse techniques

HTML reuse is a term that is rarely mentioned. Tod...

Vue implements book management case

This article example shares the specific code of ...

React configuration px conversion rem method

Install related dependencies npm i lib-flexible -...

Slot arrangement and usage analysis in Vue

The operating environment of this tutorial: Windo...

HTML+CSS to create heartbeat special effects

Today we are going to create a simple heartbeat e...

JS+AJAX realizes the linkage of province, city and district drop-down lists

This article shares the specific code of JS+AJAX ...

Solution to changing the data storage location of the database in MySQL 5.7

As the data stored in the MySQL database graduall...

Implementation of Nginx Intranet Standalone Reverse Proxy

Table of contents 1 Nginx Installation 2 Configur...

How to use MyCat to implement MySQL master-slave read-write separation in Linux

Table of contents Linux-Use MyCat to implement My...

Use of docker system command set

Table of contents docker system df docker system ...

About React Native unable to link to the simulator

React Native can develop iOS and Android native a...

Several situations where div is covered by iframe and their solutions

Similar structures: Copy code The code is as foll...

An example of the difference between the id and name attributes in input

I have been making websites for a long time, but I...