Deploy the springboot project in idea to the remote docker container

Keywords: Programming Docker Java Maven Tomcat

1. Create the project in idea, as shown below

2. Configure docker maven plugin

<!-- Docker maven plugin -->
        <!-- docker Address of private server -->
        <!--Dependent base image-->
        <cmd>["java", "-version"]</cmd>
        <entryPoint>["java", "-jar", "./${}.jar"]</entryPoint>

3. Start the server and start docker (server address

4. idea connects to docker, as shown below

If the connection is unsuccessful, check whether the Docker has enabled remote access. If not, the configuration is as follows

On the server: vim /usr/lib/systemd/system/docker.service
#Modify ExecStart line
ExecStart=/usr/bin/dockerd  -H tcp:// -H unix:///var/run/docker.sock

#Reload profile
systemctl daemon-reload    
#Restart service
systemctl restart docker.service 
#Check whether the port is on
netstat -nlpt 
#Directly curl to see if it is effective

5. Create the DockerFile file as follows

Dockerfile content

#Indicates using the Jdk8 environment as the base image. If the image is not local, it will be downloaded from the DockerHub
FROM java:8

#VOLUME points to a directory of / tmp. Because Spring Boot uses the built-in Tomcat container, Tomcat uses / tmp as the working directory by default.
#The effect of this command is to create a temporary file in the host's / var/lib/docker directory and link it to the / tmp directory in the container

#Copy file and rename
ADD ./target/springboot-docker-demo-1.0.0.jar /docker-demo-1.0.0.jar

RUN bash -c 'touch /docker-demo-1.0.0.jar'
#In order to shorten the startup time of Tomcat, add the system attribute of to point to / dev/urandom as ENTRYPOINT
ENTRYPOINT ["java","","-jar","/docker-demo-1.0.0.jar"]

6. Edit the idea Dockerfile configuration, as shown below

7. To create a docker image, click "Build Image for Dockerfile" in the dockerfile

The deployment log prompt of the console is as follows

View image in server docker

8. To run the project, click "Run Dockerfile" in the dockerfile

The results of console operation are as follows

Check the operation of the project in the server docker, as follows

9. To access the project in the browser, enter the address in the browser address bar:, and the output is as follows

Posted by lou28 on Sun, 26 Jan 2020 07:00:26 -0800