Deploying a Spring Boot Application with Docker Using IntelliJ IDEA

This tutorial walks through preparing the environment, configuring Docker remote access, creating a Spring Boot project in IntelliJ IDEA, setting up Maven and Docker files, building the image, and running the container, demonstrating a complete end‑to‑end Java microservice deployment with Docker.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Deploying a Spring Boot Application with Docker Using IntelliJ IDEA

Idea is a powerful Java IDE, Spring Boot is the most popular microservice framework in the Java ecosystem, and Docker is the hottest container technology; combining them creates an efficient development workflow.

1. Preparation

Install Docker ( official docs ) and configure the remote daemon port. Edit vi /usr/lib/systemd/system/docker.service to add -H tcp://0.0.0.0:2375 to the ExecStart line, then restart Docker:

systemctl daemon-reload
systemctl start docker

Open the port on the firewall:

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

Install the Docker plugin in IntelliJ IDEA and restart the IDE.

2. Create Spring Boot Project

Generate a Spring Boot project (e.g., via Spring Initializr) and import it into IDEA. The project structure is shown in the image.

(1) pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>docker-demo</groupId>
    <artifactId>com.demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <docker.image.prefix>com.demo</docker.image.prefix>
        <java.version>1.8</java.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <dockerDirectory>src/main/docker</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <tasks>
                                <copy todir="src/main/docker" file="target/${project.artifactId}-${project.version}.${project.packaging}"/>
                            </tasks>
                        </configuration>
                        <goals><goal>run</goal></goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>
</project>

(2) Dockerfile

FROM openjdk:8-jdk-alpine
ADD *.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

(3) application.properties

logging.config=classpath:logback.xml
logging.path=/home/developer/app/logs/
server.port=8990

(4) DockerApplication.java

@SpringBootApplication
public class DockerApplication {
    public static void main(String[] args) {
        SpringApplication.run(DockerApplication.class, args);
    }
}

(5) DockerController.java

@RestController
public class DockerController {
    static Log log = LogFactory.getLog(DockerController.class);

    @RequestMapping("/")
    public String index() {
        log.info("Hello Docker!");
        return "Hello Docker!";
    }
}

After adding the above files, configure the Docker image name and tag (e.g., docker-demo:1.1), bind host ports, and mount host directories for log persistence.

3. Build and Run

Execute Maven packaging to produce the JAR, then run the Docker build and start the container. The process pulls the base image, builds the custom image, and deploys it to the remote Docker host.

Finally, access the application via a browser (e.g., http://<host>:8990/) and verify the logs inside the mounted directory.

Through these steps, the Spring Boot Java web application is successfully containerized and deployed with Docker, illustrating a simple yet powerful workflow.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaDockermavencontainerizationSpring BootIntelliJ IDEA
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.