Deploy a Spring Boot Application to Docker with IDEA: Step‑by‑Step Guide

This tutorial walks you through preparing the environment, configuring Docker remote access, setting up a Spring Boot project in IDEA, creating Dockerfiles and Maven settings, building the image, running the container, and verifying the deployment via browser and logs.

Java Backend Technology
Java Backend Technology
Java Backend Technology
Deploy a Spring Boot Application to Docker with IDEA: Step‑by‑Step Guide

Development Preparation

Install Docker (see Docker documentation ) and configure the remote API by editing /usr/lib/systemd/system/docker.service to add -H tcp://0.0.0.0:2375, then reload and restart Docker:

vi /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl start docker

Open the Docker port in the firewall:

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

Install the IDEA Docker plugin and restart the IDE.

Connect IDEA to Remote Docker

Edit the Docker configuration in IDEA, add the remote address tcp://<your‑host>:2375, and verify the connection lists remote containers and images.

Create Spring Boot Project

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

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>

Dockerfile (src/main/docker/Dockerfile)

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

application.properties (src/main/resources)

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

DockerApplication.java

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

DockerController.java

@RestController
public class DockerController {
    static Log log = LogFactory.getLog(DockerController.class);
    @RequestMapping("/")
    public String index() {
        log.info("Hello Docker!");
        return "Hello Docker!";
    }
}

Build and Run

Package the project with Maven, which copies the JAR into the Docker build context:

Build the Docker image and run the container (replace docker-demo:1.1 with your tag):

docker build -t docker-demo:1.1 .
 docker run -d -p 8990:8990 --name docker-server docker-demo:1.1

After the container starts, open a browser and navigate to http://<your‑host>:8990/ to see the "Hello Docker!" response.

Check the container logs to verify the application output:

With these steps, the Spring Boot application is successfully containerized and deployed via IDEA and Docker.

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 BootIDEA
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

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.