Docker Compose 生产级微服务编排规范
遵循高可用架构标准,打造健壮的本地微服务拓扑:
1. 核心编排模版示例
version: '3.8'
services:
database:
image: postgres:16-alpine
restart: always
environment:
POSTGRES_DB: app_production
POSTGRES_USER: user
POSTGRES_PASSWORD: securepassword
volumes:
- pg_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U user -d app_production"]
interval: 10s
timeout: 5s
retries: 5
networks:
- internal_backend
web-api:
build:
context: .
target: runner
restart: on-failure
ports:
- "8080:8080"
depends_on:
database:
condition: service_healthy
networks:
- internal_backend
- public_ingress
networks:
internal_backend:
internal: true
public_ingress:
volumes:
pg_data: