Zero-to-One Guide for Docker Orchestration and Deployment
Prerequisites
This walkthrough assumes a Spring-Boot microservice already exists. Clone it to the server that will run the containers and make sure Docker and Docker Compose are installed.
Key Concepts in 60 Seconds
- Dockerfile – recipe that producees an immutable image.
- docker build – CLI command that turns the recipe into an image.
- Compose file – YAML description of every container, network, and volume that makes up the whole system.
Multi-Stage Dockerfile for a Spring-Boot Service
# build stage
FROM maven:3.9-eclipse-temurin-17 AS build
WORKDIR /workspace
COPY pom.xml .
COPY src ./src
RUN mvn -B -q package -DskipTests
# runtime stage
FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
COPY --from=build /workspace/target/app.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
Save the file as Dockerfile in the repository root.
Building the Image
docker build -t backend:1.0.0 .
The -t flag assigns a name and tag; the trailing dot sets the build context to the current directory.
Private Registry Push
Log in to your registry (example uses Tencent Cloud Container Registry):
docker login ccr.ccs.tencentyun.com
docker tag backend:1.0.0 ccr.ccs.tencentyun.com/acme/backend:1.0.0
docker push ccr.ccs.tencentyun.com/acme/backend:1.0.0
Compose File for the Full Stack
version: "3.9"
services:
api:
image: ccr.ccs.tencentyun.com/acme/backend:1.0.0
restart: unless-stopped
ports:
- "8080:8080"
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/appdb?useSSL=false&serverTimezone=UTC
SPRING_DATASOURCE_USERNAME: app
SPRING_DATASOURCE_PASSWORD: appsecret
depends_on:
mysql:
condition: service_healthy
mysql:
image: mysql:8.0
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: rootpwd
MYSQL_DATABASE: appdb
MYSQL_USER: app
MYSQL_PASSWORD: appsecret
ports:
- "3306:3306"
volumes:
- dbdata:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
volumes:
dbdata:
Save the file as compose.yml.
Launch Everything
docker compose -f compose.yml up -d
Check the logs:
docker compose logs -f
When the api service logs Started Application in ... seconds, the stack is ready.
Quick Health Check
curl http://localhost:8080/actuator/health
A {"status":"UP"} response confirms the orchestration is working.