In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces idea how to quickly package the SpringBoot project Docker image and deployment related knowledge, the content is detailed and easy to understand, simple and quick operation, has a certain reference value, I believe that after reading this idea how to quickly achieve the SpringBoot project packaging Docker image and deployment article will have a harvest, let's take a look.
1. Modify the configuration file of docker
Modify the file information path as follows:
/ etc/docker/daemon.json
Add the following 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 enables remote access, and unix is local access. If local access is not enabled, the following errors will occur when used 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 command in turn:
# reload configuration file systemctl daemon-reload # restart service systemctl restart docker.service # check whether the default port 2375 netstat-anp is open | grep 2375
two。 Configure port open
Execute the following commands in turn
Add the specified port to be opened: firewall-cmd-- zone=public-- add-port=2375/tcp-- permanent reload the added port: firewall-cmd-- reload query whether the specified port is opened successfully: firewall-cmd-- query-port=2375/tcp
Note: the above configuration is carried out when the firewall is enabled. If the system firewall is not enabled, the above configuration is not required. For example, my server does not have a firewall configured, and the following information is displayed at runtime:
Finally, let's see if our configuration is effective.
Curl http://127.0.0.1:2375/info
If the following message appears, the configuration is successful
3.IDEA installs the Docker plug-in
If you have a higher version of idea, the docker plug-in is built in.
If not, don't worry, we can install it ourselves.
4.IDEA configuration docker
Note: my above 192.168.1.2 is my own server Ip, just change it to your docker server ip.
After clicking Apply, it will pop up in your service
Click on the link and we will find the container information of our docker configuration
5.SpringBoot Integration Docker configuration 5.1 install pom dependency
Install the plug-in: Docker-maven-plugin
Com.spotify docker-maven-plugin 1.0.0 ${project.artifactId} latest Java ninesun@qq.com / ROOT ["java" "- version"] ["java", "- jar" "${project.build.finalName} .jar"] http://192.168.1.2:2375 / ROOT {project.build.directory} ${project.build.finalName} .jar
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 org.springframework.boot spring-boot-maven-plugin com.spotify docker-maven-plugin 1.0.0 ${project.artifactId} latest java ninesun@qq.com / ROOT ["java" "- version"] ["java", "- jar" "${project.build.finalName} .jar"] http://192.168.1.2:2375 / ROOT {project.build.directory} ${project.build.finalName} .jar
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 it will lead to packaging failure. I deleted DockerApplication directly.
5.2 build Mirror
Before build image, we need to package the project.
Enter our project directory through cmd
Execution
Mvn docker:build
The following message indicates that the package is successful
Next, back to our idea, we can see
This is the image we packed.
Execute on the server
Docker images
You can also see the information of the image.
5.3 start the mirror
Execute in our server
Docker run-d-name idea-docker-test-p 8089 docker
Note: the reason why I exposed port 8089, as long as it is because of 8080 conflict, it is good to see my own situation to change.
Next, let's visit the test interface we wrote:
You can see that it has been successfully deployed and accessible at the same time.
We can see the log of the image and output that we have just started successfully in Idea.
This is the end of the article on "how idea can quickly package and deploy a Docker image of a SpringBoot project". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to quickly package the SpringBoot project into a Docker image and deploy it". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.