


How does idea quickly package the SpringBoot project into a Docker image and deploy it?
1. Modify the docker configuration file
Modify the file information path as follows:
/etc/docker/daemon.json
Add the following content to the configuration file:
"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]
Note: If you don’t have this daemon.json, create one yourself in the /etc/docker/ directory
touch daemon.json
tcp is for remote access, and unix is for local access. If local access is not enabled, the following error will occur when using it on the server:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running ?
After the modification is completed, execute the following commands in sequence:
#重新加载配置文件 systemctl daemon-reload # 重启服务 systemctl restart docker.service # 查看端口是否开启 默认端口2375 netstat -anp|grep 2375
添加指定需要开放的端口: firewall-cmd --zone=public --add-port=2375/tcp --permanent 重载入添加的端口: firewall-cmd --reload 查询指定端口是否开启成功: firewall-cmd --query-port=2375/tcpNote: The above configurations are all performed when the firewall is turned on. If the system firewall is not turned on, the above configuration is not required. For example, my server does not have a firewall configured. Run The following information is displayed:
curl http://127.0.0.1:2375/infoIf the following information appears, the configuration is successful
##4.IDEA configure docker
Note: I mentioned above 192.168.1.2 is my own server IP. Just change it to the server IP where your docker is located.
Click to connect, and we will find that our docker configuration Container information
5. SpringBoot integrated Docker configuration
5.1 Install pom dependencies
Install plug-in: Docker-maven-plugin
<!--docker-maven-plugin插件打包--> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.0.0</version> <configuration> <!--镜像名称--> <imageName>${project.artifactId}</imageName> <!--指定标签--> <imageTags> <imageTag>latest</imageTag> </imageTags> <!--基础镜像jdk1.8--> <baseImage>java</baseImage> <!--制作者提供本人信息--> <maintainer>ninesun@qq.com</maintainer> <!--切换到Root目录--> <workdir>/ROOT</workdir> <cmd>["java", "-version"]</cmd> <entryPoint>["java", "-jar", "${project.build.finalName}.jar"]</entryPoint> <!--指定DockerFile路径--> <!-- <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>--> <!--指定远程docker api地址--> <dockerHost>http://192.168.1.2:2375</dockerHost> <!-- 这里是复制 jar 包到 docker 容器指定目录配置 --> <resources> <resource> <targetPath>/ROOT</targetPath> <!--用于指定需要复制的根目录--> <directory>${project.build.directory}</directory> <!--用于指定需要复制的jar文件--> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin>
All my maven configurations are as follows:
4.0.0 org.springframework.boot spring-boot-starter-parent 2.6.6 com.example docker 0.0.1-SNAPSHOT docker docker 11 true true org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test <!--docker-maven-plugin插件打包--> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.0.0</version> <configuration> <!--镜像名称--> <imageName>${project.artifactId}</imageName> <!--指定标签--> <imageTags> <imageTag>latest</imageTag> </imageTags> <!--基础镜像jdk1.8--> <baseImage>java</baseImage> <!--制作者提供本人信息--> <maintainer>ninesun@qq.com</maintainer> <!--切换到Root目录--> <workdir>/ROOT</workdir> <cmd>["java", "-version"]</cmd> <entryPoint>["java", "-jar", "${project.build.finalName}.jar"]</entryPoint> <!--指定DockerFile路径--> <!-- <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>--> <!--指定远程docker api地址--> <dockerHost>http://192.168.1.2:2375</dockerHost> <!-- 这里是复制 jar 包到 docker 容器指定目录配置 --> <resources> <resource> <targetPath>/ROOT</targetPath> <!--用于指定需要复制的根目录--> <directory>${project.build.directory}</directory> <!--用于指定需要复制的jar文件--> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> org.springframework.boot spring-boot-maven-plugin
Note: After we successfully pull the plug-in, we will find that the directory structure becomes as follows:
We need to delete a startup class, otherwise the packaging will fail. I deleted the DockerApplication directly
5.2 build image
Before building the image, we need to package the project first Operation
Enter our project directory through cmd
Execute
mvn docker:build
The following information appears Indicates successful packaging
Next, return to our idea, you can see that
This is what we packaged Mirror
docker images
You can also see the image information
5.3 Start the mirror
on our server Execute within
docker run -d --name idea-docker-test -p 8089:8080 docker
Note: The reason why I exposed port 8089 is because of a conflict with 8080. You can change it according to your own situation
Continue Let’s visit the test interface we wrote:
You can see that it has been successfully deployed and can also be accessed successfully
We can see that it can also be viewed in Idea Let’s get to the image we just started successfully and the log output
The above is the detailed content of How does idea quickly package the SpringBoot project into a Docker image and deploy it?. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools