How to Quickly Package and Deploy a SpringBoot Microservice with Docker on Windows
This guide walks through setting up a Windows development environment, enabling Hyper‑V, installing Docker Desktop, building a SpringBoot JAR with Maven, creating Dockerfiles, running containers via IDEA and the command line, and finally deploying the image to a Linux server with proper volume and port mappings.
Background
The new backend project uses a micro‑service framework with Gateway, Nacos, and other services, and needs a simple Docker‑based deployment method that works from a Windows development machine.
Why Docker and Why Windows
Docker containers simplify packaging, deployment, and management of backend programs; using Docker Swarm or Kubernetes can orchestrate multiple containers. The developer works on Windows, builds Docker images there, and pushes them to a Linux server.
Common Questions
Can Docker run on Windows? Yes.
Do code changes require rebuilding the image? No, you can replace the JAR via a Docker volume.
Why not use Jenkins? The project is new, so a lightweight approach is preferred.
2. Running Docker on Windows
2.1 Principle
Docker needs a Linux kernel; on Windows this is provided by a virtual Linux environment.
2.2 Enable Hyper‑V
Hyper‑V is required (Windows 10 Pro/Edu/Enterprise). Enable it via
Control Panel → Programs and Features → Turn Windows features on or off → Hyper‑V.
2.3 Install Docker for Windows
Download Docker Desktop from the official site and follow the installer. Verify installation by running docker run hello-world in PowerShell.
3. Building the Image with IDEA
IDEA provides Docker integration.
3.1 Maven Build JAR
Run mvn package to produce operation-core-0.0.1-SNAPSHOT.jar, then rename it to operation.jar.
3.2 Write Dockerfile
A Dockerfile defines the image build steps. Example:
# Pull base image
FROM hub.c.163.com/library/java:latest
MAINTAINER wukong <[email protected]>
RUN mkdir -p /apps
ADD passjava-demo-1.0.jar /apps/passjava-demo.jar
ENV TZ "Asia/Shanghai"
EXPOSE 9600
ENTRYPOINT ["java","-jar","/apps/passjava-demo.jar"]3.3 Configure and Run Dockerfile in IDEA
Create a Docker run configuration pointing to the Dockerfile; IDEA pulls the base image, builds the image, and starts a container.
3.4 Test the Container
Use curl http://localhost:9600/test to call the REST API. If the request fails, check container logs and ensure port mapping is configured.
curl http://localhost:9600/test3.5 Custom Container Configuration
Define a custom container run configuration with explicit port mapping (e.g., -p 9600:9600) and volume mounts. After starting, the service becomes reachable.
4. Deploying to a Linux Server
4.1 Deployment Idea
Save the Docker image as a tar archive, transfer it to the server, load it, and run the container with proper volume and port settings.
4.2 Steps
Save image:
docker save passjava-docker-demo-23.02 -o D:\passjava-demo.tarCopy the tar file to the Linux host.
Load image: docker load -i passjava-demo.tar Run 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.02If the container cannot find the JAR, ensure the host /nfs-data/service/apps directory contains the JAR file.
After the container starts, verify the service with curl http://<server_ip>:9600/test and confirm the expected response.
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.
Su San Talks Tech
Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.
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.
