Backend Development 10 min read

Docker Packaging and Deployment Guide for a Windows‑based Spring Boot Microservice

This article explains how to set up Docker on Windows, create a Dockerfile for a Spring Boot microservice, build the image with Maven and IDEA, test the container, and finally export, transfer, and run the image on a Linux server with proper volume and port mappings.

IT Services Circle
IT Services Circle
IT Services Circle
Docker Packaging and Deployment Guide for a Windows‑based Spring Boot Microservice

The article begins by describing the project background: a new microservice framework with a gateway, Nacos registry, and other services needs a simple Docker‑based deployment method, especially when development is done on a Windows machine.

It explains why Docker is chosen—to simplify packaging, deployment, and management of backend programs—and why Windows is relevant, as developers use Windows + IDEA to build Docker images that are later run on Linux servers.

Windows Docker setup : The guide shows how to enable Hyper‑V (Windows 10 Enterprise/Professional/Education) via Control Panel → Programs and Features → Turn Windows features on or off → Hyper‑V and provides the Microsoft documentation link ( https://learn.microsoft.com/zh-cn/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v ). It then directs users to download Docker Desktop for Windows from the official site ( https://www.docker.com/products/docker-desktop/ ) and verify the installation with docker run hello-world .

IDEA image building : Using IDEA, the process is split into two main steps: (1) Maven builds the Spring Boot JAR ( mvn package ), producing operation-core-0.0.1-SNAPSHOT.jar (renamed to operation.jar ); (2) a Dockerfile is written to base on a Java image, copy the JAR, set timezone, expose port 9600, and define the entrypoint. The Dockerfile content is:

# 拉取指定的镜像文件
FROM hub.c.163.com/library/java:latest

# MAINTAINER 指令允许你给将要制作的镜像设置作者信息
MAINTAINER wukong <[email protected]>

# 容器内创建一个 apps 目录,用来挂载 jar 包
RUN mkdir -p /apps

# 将 passjava-demo-1.0 jar 包复制到 /apps/passjava-demo.jar
ADD passjava-demo-1.0.jar /apps/passjava-demo.jar

# 设置时区
ENV TZ "Asia/Shanghai"

# 设置暴露的端口
EXPOSE 9600

# 运行 Java 应用程序的命令
ENTRYPOINT ["java","-jar","/apps/passjava-demo.jar"]

IDEA creates a Docker run configuration that pulls the Java base image, builds the container, and starts it. Initial tests using curl http://localhost:9600/test reveal a missing port mapping, which is fixed by configuring the container with proper port forwarding.

Custom container configuration : The guide shows how to define a custom container in IDEA, ensuring the image is used and ports are correctly mapped, resulting in successful API access.

Server deployment : To move the image to a Linux server, the image is saved as a tar archive with docker save passjava-docker-demo-23.02 -o D:\passjava-demo.tar , transferred to the server, and loaded via docker load -i passjava-demo.tar . The container is then started with volume 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

After fixing a missing JAR in the mounted /apps directory, the service runs correctly and responds to curl http://localhost:9600/test with the expected output.

DockerMicroservicesDeploymentSpringBootwindowsIDEA
IT Services Circle
Written by

IT Services Circle

Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.

0 followers
Reader feedback

How this landed with the community

login 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.