Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of IDEA connection to remote server Docker deployment Spring Boot project

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Editor this time to share with you is a detailed explanation of the IDEA connection to the remote server Docker deployment Spring Boot project, the article is rich in content, interested partners can learn about it, I hope you can get something after reading this article.

Preparatory work before the start

I own a CentOS7. Mine is a Tencent Cloud CVM.

Tencent Cloud server installs Docker. My version is Docker 19.03.9. For more information on installing and configuring Image Accelerator, please refer to my other blog post: https://www.jb51.net/article/188048.htm.

IDEA is installed on Windows

Officially start work.

Step 1: configure Docker and enable remote access (Note: for reference only, the actual production environment is absolutely impossible, which will cause great security risks). The default port is 2375, which can also be changed to other ports.

1. Modify / lib/systemd/system/docker.service file

Vim / lib/systemd/system/docker.service

Append-H tcp://0.0.0.0:2375-H unix://var/run/docker.sock after ExecStart

Remember to write, save and exit command after modification: wq

2. Reload the configuration file and restart docker to make the configuration take effect.

# reload configuration file systemctl daemon-reload# restart docker service systemctl restart docker

3. Use the curl command to check whether it is turned on.

# curl downloads the service information of docker curl http://127.0.0.1:2375/info

If there is a return description, it proves that it has been enabled successfully. You can see my Docker version, image accelerator address and other information, but at this time the remote may not be able to access it.

4. Configure Tencent Cloud security group rules. Open port 2375 in the inbound rules to allow remote access (Ali Cloud is the same)

OK will be finished at the last point.

5. Check whether the port can be accessed remotely, and enter: http:// server IP address: 2375/info in the local browser

Step 2: configure the project to connect to the remote docker

1. Install the Docker plug-in, go to Plugins to search for Docker, and then install it directly. If I have already installed it, restart IDEA after the installation is complete, and you will have the docker plug-in.

2. Configure the remote docker to connect, open the Docker plug-in, create a new connection, enter the server IP address: 2375 at the Engine API URL, and then, if nothing happens, Connection successful will appear below, so that the Docker connecting to the remote server is successful.

3. Edit the project pom.xml file and add the docker-maven-plugin plug-in to the Spring Boot project.

Com.spotify docker-maven-plugin 1.0.0 build-image package build wbb/$ {project.artifactId} latest ${project.basedir} http://134.175.236.221:2375 / ${project.build.directory} ${project.build.finalName} .jar

4. Create a Dockerfile file in the project root directory

Dockerfile file content

The parsing of Dockerfile reserved words can be found in another of my blog posts: https://www.jb51.net/article/102902.htm, which contains detailed parsing of commonly used reserved words, but there is no example, which can be compared and understood in this Dockerfile file.

The content of this Dockerfile file is about:

The first line: the image to be created is based on the java:8 image, that is, JDK8, that is, the basic Java running development environment. This can also be docker pull in advance.

Second line: add the jar package under the target directory to the image when building, and rename it to app.jar

The third line: the port on which the image is open to the outside world is 8888, which is also used later for port mapping. Be sure to remember, of course, if you don't remember, you can also use the docker history command to see it.

Line 4: the java-jar / app.jar command is automatically executed when the mirror instance container is started, that is, when the container is started, the project is started and will not be overridden by the command parameters added when the container is started

In addition, other unspecified parameters are default, for example, when logging into the container, the default path is the root directory

5. Package the project and build the image automatically. Click the Maven Projects on the right, and then double-click package

If you see the message, it means that the build is successful, and now you can go to the server to view the built image.

Step 3: start the mirror instance container and access the project remotely. The next steps can be done directly in IDEA or on the server. In order to be more familiar with the docker command, I demonstrated it on the server side.

You can check out my other two blog posts about the following docker commands: https://www.jb51.net/article/113227.htm https://www.jb51.net/article/142481.htm, which has a detailed explanation of the docker mirror command and the container command.

1. View all images: docker images

As shown in the figure, the mirror wbb/shop image you just built already exists

2. Launch container: docker run-it-p 8889Switzerland 8888-- name shop wbb/shop

When starting up, the-p 8889 8888 here is a port mapping, that is, port 8889 of the host is mapped to port 8888 of the mirror. Accessing port 8889 of the host is equivalent to accessing port 8888 of the mirror. This 8888 is the open port written in the Dockerfile file. Of course, generally it should be designated to run in the background, and I specify the foreground to run interactively. In fact, it is just for the beauty and figure of the picture. The goddess of dreams.

3. View container running status information: docker ps

As you can see, the constructed mirror instance has been running for more than 7 minutes. In the case of port mapping, the first one is the container's ID.

4. Remote access project: http:// server IP address: 8889/shop

Before that, you must make sure that port 8889 of the host is open, otherwise port 8889 can be released according to the rules for configuring security groups, and / shop is the virtual path of my project.

OK, at this point, the method of using IDEA to connect to a remote Docker service to deploy a Spring Boot project is explained. Please give us more advice on the shortcomings.

After reading this article on the detailed explanation of the IDEA connection to the remote server Docker deployment Spring Boot project, if you think the content of the article is good, you can share it with more people.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report