Deploying a Spring Boot Application to Docker Using IntelliJ IDEA
This tutorial walks through installing Docker, configuring remote access, creating a Spring Boot project with Maven, adding Docker support via plugins, writing Dockerfile and application code, building the image, and running the container, demonstrating a complete end‑to‑end deployment workflow.
This guide explains how to combine IntelliJ IDEA, Spring Boot, and Docker to create and deploy a Java web application.
1. Docker installation and remote configuration – Install Docker (see official docs) and edit vi /usr/lib/systemd/system/docker.service to add -H tcp://0.0.0.0:2375 to the ExecStart line, then reload and start the daemon and open the port with firewall-cmd --zone=public --add-port=2375/tcp --permanent.
2. Create a Spring Boot project – Use IDEA to generate a Maven project, configure the pom.xml with Spring Boot parent 2.0.2.RELEASE, add dependencies for spring-boot-starter-web, spring-boot-starter-test, and log4j, and include the docker-maven-plugin and maven-antrun-plugin for Docker image creation.
3. Add Docker support – Create src/main/docker/Dockerfile containing:
FROM openjdk:8-jdk-alpine<br/>ADD *.jar app.jar<br/>ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]4. Application code – Add @SpringBootApplication class DockerApplication, a
@RestController DockerControllerthat logs and returns "Hello Docker!", and an application.properties file configuring logging path and server port.
5. Build and run – Execute mvn package to build the JAR, then use the Docker Maven plugin to build the image (e.g., docker-demo:1.1) and run a container named docker-server. Verify the container logs and access the application via a browser at the mapped port.
By following these steps, the Spring Boot web service is containerized and can be deployed and managed easily with Docker.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
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.
