Docker + Intellij IDEA, increase productivity by 10 times!

IDEA is a powerful tool for java development, springboot is the most popular micro service framework in the Java ecosystem, and docker is the hottest container technology at present. What chemical reaction will they produce together?

1, Preparation before development

1.Docker installation

Refer to:

2. Configure docker remote connection port

vi /usr/lib/systemd/system/docker.service  

Find ExecStart and add - H on the last side tcp:// , as shown in the figure below


3. Restart docker

systemctl daemon-reload  
systemctl start docker  

4. Open port

firewall-cmd --zone=public --add-port=2375/tcp --permanent    

5. Install the plug-in for idea and restart it


6. Connect to remote docker

1. Edit configuration


2. Fill in the remote docker address

3. If the connection is successful, the remote docker container and image will be listed

2, New project

1. Create a springboot project

Project structure diagram


1. Configuring pom files

<?xml version="1.0" encoding="UTF-8"?>  
<project xmlns=""  
        <relativePath />  
                            <copy todir="src/main/docker" file="target/${project.artifactId}-${project.version}.${project.packaging}"></copy>  

2. Create a docker directory under src/main directory and a Dockerfile file

FROM openjdk:8-jdk-alpine  
ADD *.jar app.jar  
ENTRYPOINT ["java","","-jar","/app.jar"]  

3. Create the file in the resource directory


4. Create DockerApplication file

public class DockerApplication {  
    public static void main(String[] args) { , args);  

5. Create DockerController file

public class DockerController {  
    static Log log = LogFactory.getLog(DockerController.class);  
    public String index() { "Hello Docker!");  
        return "Hello Docker!";  

6. Add configuration

Command interpretation:

  • Image tag: specify the image name and tag. The image name is docker demo and the tag is 1.1
  • Bind ports: bind the host port to the container internal port. Format is [host port]: [container internal port]
  • Bind mounts: hang the host directory into the internal directory of the container.

The format is [Host Directory]: [container internal directory]. The springboot project will print the log in the container / home/developer/app/logs / directory. After the host directory is mounted to the internal directory of the container, the log will be persisted in the host directory outside the container.

7. Maven pack

8. Run

First pull the basic image, then package the image, and deploy the image to the remote docker for operation


Here we can see that the image name is docker Demo: 1.1 and the docker container is docker server

9. Run successfully

10. Browser access


11. Log view


Since then, the springboot project has been successfully deployed to docker through IDEA! It's hard to imagine how easy it is to deploy a Java Web project!

Thanks for reading, hope to help you:) Source:

- EOF -

Posted by Griff1324 on Thu, 25 Nov 2021 17:09:33 -0800