One‑Click Deployment of a SpringBoot Application Using IDEA and Docker
This tutorial demonstrates how to replace the traditional jar‑upload workflow with an IDEA‑integrated Docker solution, covering environment setup, SSH configuration, Docker daemon connection, SpringBoot code, Dockerfile creation, remote deployment settings, firewall opening, and common troubleshooting steps.
1. Traditional Deployment Method
Usually a SpringBoot project is packaged into a JAR, uploaded to a server, and started with java -jar . Re‑deploying requires repeating these steps and makes log inspection cumbersome.
2. Prerequisites
Server with Docker installed and able to pull images
Basic knowledge of Dockerfile syntax
IntelliJ IDEA installed locally
A SpringBoot project that can be accessed via HTTP
3. SSH Configuration
Configure an SSH connection in IDEA settings by providing host, username and password, then test the connection.
4. Connect to Docker Daemon
In IDEA settings, add a Docker configuration, choose the SSH method, select the previously created SSH entry, and apply the changes.
5. Create a Simple SpringBoot Application
Implement a minimal controller that returns a simple HTML string on port 11020 :
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
@GetMapping("/")
public String index() {
return "
Hello, world
";
}
}6. Write a Dockerfile
Place the Dockerfile next to the JAR file and use the following content (adjust as needed):
# Base image
FROM openjdk:17
# Copy the JAR into the image
ADD target/one-click-deployment-0.0.1-SNAPSHOT.jar /one-click-deployment-0.0.1-SNAPSHOT.jar
# Entry point
ENTRYPOINT ["java", "-jar", "/one-click-deployment-0.0.1-SNAPSHOT.jar", "--spring.profiles.active=prod"]
# Expose the service port
EXPOSE 110207. Configure Remote Deployment in IDEA
7.1 Create Configuration
Check “Store as project file”
Give a custom name
Select the Docker daemon created in step 4
Choose the Dockerfile created in step 6
Set image tag and container name
7.2 Bind Port
Map the container port 11020 to a host port of your choice.
7.3 Add Pre‑Deployment Tasks
Add Maven goals clean and package so the JAR is built before the Docker image is created.
8. Deploy the Project
Click the green run triangle in IDEA; the project will be built, the Docker image created, and the container started automatically. Logs appear in the IDEA console.
9. Open Firewall Port 11020
Ubuntu: sudo ufw allow 11020 sudo ufw reload
CentOS: sudo firewall-cmd --zone=public --add-port=11020/tcp --permanent sudo firewall-cmd --reload
10. Access the Application
Open a browser and navigate to http:// :11020/ to see the “Hello, world” page.
11. Common Issues
11.1 Cannot connect to the Docker daemon
Make sure the SSH user belongs to the docker group:
sudo usermod -aG docker $USER
getent group dockerRestart IDEA after adding the user.
11.2 No main manifest attribute in the JAR
This indicates the JAR lacks an entry point. Ensure the spring-boot-maven-plugin is enabled and the mainClass is specified in pom.xml .
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.
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.