Deploying a Spring Boot Application with Docker Using IntelliJ IDEA
This tutorial explains how to install Docker, configure remote access, create a Spring Boot project in IntelliJ IDEA, add Dockerfile and Maven settings, build a Docker image, run the container, and verify the application through a browser and log inspection.
IDEA is a powerful Java development tool, Spring Boot is the most popular micro‑service framework in the Java ecosystem, and Docker is the leading container technology; this guide shows how to combine them to quickly deploy a Java web application.
1. Docker installation – Follow the official Docker documentation (https://docs.docker.com/install/). Then edit the Docker service file to enable remote TCP access: vi /usr/lib/systemd/system/docker.service Append -H tcp://0.0.0.0:2375 to the ExecStart line, reload the daemon and start Docker:
systemctl daemon-reload
systemctl start dockerOpen the port permanently:
firewall-cmd --zone=public --add-port=2375/tcp --permanent2. Create a Spring Boot project – Use IDEA to generate a Spring Boot project. The pom.xml should contain the Spring Boot parent and the Docker Maven plugin:
<?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>
...
<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>
</plugins>
</build>
</project>3. Add Docker support – Create src/main/docker/Dockerfile:
FROM openjdk:8-jdk-alpine
ADD *.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]Configure src/main/resources/application.properties for logging and port:
logging.config=classpath:logback.xml
logging.path=/home/developer/app/logs/
server.port=89904. Write the application code – Main class:
@SpringBootApplication
public class DockerApplication {
public static void main(String[] args) {
SpringApplication.run(DockerApplication.class, args);
}
}Simple controller:
@RestController
public class DockerController {
static Log log = LogFactory.getLog(DockerController.class);
@RequestMapping("/")
public String index() {
log.info("Hello Docker!");
return "Hello Docker!";
}
}5. Build and run – Package the project with Maven, then let the Docker Maven plugin build the image (e.g., docker-demo:1.1) and start a container exposing port 8990. Verify the service by opening http://<host>:8990 in a browser and checking the logs inside the mounted directory.
By following these steps, a Spring Boot Java web application can be containerized and deployed with Docker directly from IntelliJ IDEA, demonstrating a streamlined workflow for modern backend development.
IT Xianyu
We share common IT technologies (Java, Web, SQL, etc.) and practical applications of emerging software development techniques. New articles are posted daily. Follow IT Xianyu to stay ahead in tech. The IT Xianyu series is being regularly updated.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
