In the previous article (manually create an image file) wrote in the server manually create a SpringBoot image and run the use of this time to write a tutorial through IDEA directly package image into the server docker run.

1. Install the plug-in and obtain docker support

If Intellij IDEA is released in 2019 or later and Docker comes with it, you don’t need to install it.

2. Connect to remote Docker

This step is to obtain the docker of the remote server. Once the connection is successful, it can obtain its image, container content and interface operation of the container.Note: the server address is your own, the connection uses TCP transport protocol, port number is 2375 do not change. — — — — — — — — — — — — — — — — — — manual line, now is to finish the article in the evening: the server operator sent me this:I went to see the look, opened the docker found that there are several is not my own set of container running, just know, it must be someone see me this article then the remote connection to my server, and then opened the background processes, such as mining activities, hence immediately change the port number, killed the docker and remove the mirror in the container. So don’t use the default port here, or someone can add images and open containers for you remotely if they know your IP address. — — — — — — — — — — — — — — — — –, as shown in the following tips found my connection fails, the reason may be the following: 1. After the firewall is enabled, port 2375 is not enabled. 2. The service under Docker is not set.

Solution: 1. Check the firewall Settings and port status. Disable the firewall or enable port 2375. 2. Modify the docker service file

I’m going to skip the first one, but if you’re Linux based, it’s easy to do or search for. Second: modify the docker service file

vi /usr/lib/systemd/system/docker.service
Copy the code

Open the docker service file and modify the line that will start ExecStart:

ExecStart = /usr/bin/dockerd -h TCP: // 0.0.0.00:2375 -h Unix: //var/run/docker.sockCopy the code

After completing the modification, execute the following operation (command) : the systemctl daemon is reloaded:

systemctl daemon-reload
Copy the code

Restart docker service:

service docker restart
Copy the code

The docker service will restart after the restart, port 2375 can be used for connection.Successfully connected to the remote server docker.

3. Be familiar with the Docker interface in IDEA

You can see the container and image information under the server. When I stop (or do other operations) a container on the server side, IDEA can also give timely feedback as shown in the figure below: Even IDEA has a lot of functions, such as the buttons on the left, which is the button to start and stop deleting the container. You can also see the logs of the container when it runs and some static files bound, etc., which is very strong.

Four, start the mirror

1. Prepare the Dockerfile and JAR package and store them in the SRC /main/Docker directory.

2. Add the Docker configuration and set it in run Configuration in the upper right corner.

If you manually create the image after the article, this configuration is easy to understand, Dockerfile has not changed, here is for the Docker run service configuration. This includes the location of the Dockerfile, the image name and label, the container name, the mapping port number, and Run options, where -d refers to how the daemon runs the image. You can preview the execution statements with Command Preview at the bottom. When configured, clean and package the project, then start Docker:Image successfully packaged and running:The image and container can be seen on the server:The browser successfully accessed the project:

This article is over, there is time to continue to update!