Docker Packaging and Deployment on Windows with IDEA – A Complete Guide
This article explains how to set up a Docker-based deployment workflow on Windows, covering Hyper‑V activation, Docker Desktop installation, Maven build, Dockerfile creation, IDEA integration, container testing, and final deployment to a Linux server.
1. Background
The project uses a micro‑service architecture with a gateway, Nacos registry and other services; Docker is needed to simplify packaging and management, especially when developing on a Windows machine and deploying to Linux.
2. Running Docker on Windows
2.1 Principle
Docker requires a Linux kernel; on Windows this is provided by a virtual Linux environment.
2.2 Enabling Hyper‑V
Enable Hyper‑V via Control Panel → Programs and Features → Turn Windows features on or off → Hyper‑V . See Microsoft documentation:
https://learn.microsoft.com/zh-cn/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v2.3 Installing Docker for Windows
Download Docker Desktop from the official site and install it.
https://www.docker.com/products/docker-desktop/After installation, run docker run hello-world to verify the setup.
3. Building the Image with IDEA
IDEA can build Docker images directly.
Use Maven to package the SpringBoot application into an executable JAR.
Configure IDEA to run a Dockerfile and build the image.
3.1 Maven Build JAR
Execute mvn package to generate operation-core-0.0.1‑SNAPSHOT.jar , then rename it to operation.jar .
3.2 Writing Dockerfile
A Dockerfile defines the image build steps. Example:
# Pull base image
FROM hub.c.163.com/library/java:latest
# Maintainer information
MAINTAINER wukong <[email protected]>
# Create apps directory
RUN mkdir -p /apps
# Add the JAR file
ADD passjava-demo-1.0.jar /apps/passjava-demo.jar
# Set timezone
ENV TZ "Asia/Shanghai"
# Expose port
EXPOSE 9600
# Run the Java application
ENTRYPOINT ["java","-jar","/apps/passjava-demo.jar"]3.3 Configuring and Running Dockerfile in IDEA
Create a Docker run configuration in IDEA; the IDE will pull the required JDK image, execute the Dockerfile commands, and start a container.
3.4 Testing
Test the running service with curl http://localhost:9600/test . If the request fails, check container logs and port mappings.
3.5 Custom Container in IDEA
Define a custom container configuration that includes volume mounts and port mapping, then run it to verify the service is reachable.
4. Deploying to a Server
4.1 Deployment Idea
Save the Docker image as a tar archive, transfer it to the Linux server, load it, and run the container with appropriate volume mounts and port mapping.
4.2 Deployment Steps
Save the image:
docker save passjava-docker-demo-23.02 -o D:\passjava-demo.tarCopy the tar to the server, then load it:
docker load -i passjava-demo.tarRun 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.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:// :9600/test and confirm the expected response.
Wukong Talks Architecture
Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.
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.