Cloud Native 11 min read

How to Build and Deploy a SpringBoot Docker Image on Windows Using IDEA

This guide walks through setting up Docker on Windows, creating a Dockerfile for a SpringBoot service, using IntelliJ IDEA to build the image, testing the container locally, and finally deploying the image to a Linux server with proper volume and port mappings.

Architect
Architect
Architect
How to Build and Deploy a SpringBoot Docker Image on Windows Using IDEA

Background

The project is a new micro‑service framework that includes a gateway, Nacos registry and other services. A simple Docker‑based deployment method is required, especially when development is performed on a Windows workstation.

Running Docker on Windows

Principle

Docker needs a running Linux kernel. On Windows this is provided by a lightweight Linux virtual machine that Docker Desktop creates.

Enable Hyper‑V

Hyper‑V is built into Windows 10 Pro/Enterprise/Education. Enable it via Control Panel → Programs and Features → Turn Windows features on or off → check Hyper‑V → OK . (Reference: Microsoft Docs https://learn.microsoft.com/zh-cn/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v)

Install Docker Desktop

Download Docker Desktop for Windows from the official Docker site, install with the default options, and verify the installation by running docker run hello-world in PowerShell.

Building the Docker Image with IntelliJ IDEA

IntelliJ IDEA provides Docker integration. The workflow consists of two main steps:

Package the Spring Boot application into an executable JAR using Maven.

Create a Dockerfile and let IDEA build a Docker image from it.

The sample Spring Boot application listens on port 9600 and exposes a simple REST endpoint.

Maven packaging

Execute mvn package (or use the Maven tool window) to generate operation-core-0.0.1‑SNAPSHOT.jar. Rename the file to operation.jar for brevity.

Dockerfile

Example Dockerfile:

# Pull base image
FROM hub.c.163.com/library/java:latest
MAINTAINER wukong <[email protected]>
RUN mkdir -p /apps
ADD operation.jar /apps/operation.jar
ENV TZ "Asia/Shanghai"
EXPOSE 9600
ENTRYPOINT ["java","-jar","/apps/operation.jar"]

IDEA Docker run configuration

Create a Docker run configuration that points to the Dockerfile. IDEA will pull the base image, execute the Dockerfile instructions, and start a container.

Testing the container

After the container starts, test the service with: curl http://localhost:9600/test If the request fails, inspect the logs with docker logs <container_id> and verify that host port 9600 is mapped to container port 9600.

Custom container configuration

If the automatic configuration does not include port mapping, create a custom container configuration in IDEA and add the option -p 9600:9600 (and any required volume mounts). Restart the container.

Deploying to a Linux server

Deployment workflow

Export the built image as a tar archive, transfer it to the target host, load it into Docker, and run it with the necessary volume mounts, restart policy and port mapping.

Steps

Save the image:

docker save passjava-docker-demo-23.02 -o D:\passjava-demo.tar

Copy passjava-demo.tar to the Linux server (e.g., via SCP).

Load the image on the server: docker load -i passjava-demo.tar Run the container with mounts and port mapping:

docker run --name passjava-demo -d \
  -v /nfs-data/service:/nfs-data/service \
  -v /nfs-data/service/apps:/apps \
  -v /nfs-data/service/logs:/nfs-data/service/logs \
  --restart=always \
  -p 9600:9600 \
  passjava-docker-demo-23.02

Make sure the host directory mapped to /apps contains the JAR file; otherwise the container will fail because the entrypoint cannot find the JAR.

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.

DockerSpringBootIntelliJ IDEAWindowsDockerfileContainer Deployment
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

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.