69 lines
1.9 KiB
YAML
69 lines
1.9 KiB
YAML
services:
|
||
# MySQL Database
|
||
db:
|
||
image: mysql:8.0
|
||
container_name: wmms-db
|
||
restart: unless-stopped
|
||
environment:
|
||
MYSQL_ROOT_PASSWORD: wmms1234
|
||
MYSQL_DATABASE: wmms
|
||
ports:
|
||
# 只绑本机回环:数据库不对局域网暴露。容器之间仍走内部网络,互不影响。
|
||
- "127.0.0.1:3307:3306"
|
||
volumes:
|
||
- mysql_data:/var/lib/mysql
|
||
- ./scripts/init.sql:/docker-entrypoint-initdb.d/001-init.sql:ro
|
||
command: >
|
||
--default-authentication-plugin=mysql_native_password
|
||
--character-set-server=utf8mb4
|
||
--collation-server=utf8mb4_unicode_ci
|
||
healthcheck:
|
||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-pwmms1234"]
|
||
interval: 10s
|
||
timeout: 5s
|
||
retries: 5
|
||
|
||
# Backend API (Go)
|
||
backend:
|
||
build:
|
||
context: .
|
||
dockerfile: Dockerfile
|
||
container_name: wmms-backend
|
||
restart: unless-stopped
|
||
ports:
|
||
# 只绑本机回环:后端 API 不对局域网暴露。前端经 Nginx 走容器内部网络
|
||
# 反代(proxy_pass http://backend:8082),不经过宿主机端口,故不受影响。
|
||
- "127.0.0.1:8082:8082"
|
||
environment:
|
||
DB_DSN: "root:wmms1234@tcp(db:3306)/wmms?charset=utf8mb4&parseTime=true"
|
||
GIN_MODE: release
|
||
volumes:
|
||
- uploads_data:/app/uploads
|
||
depends_on:
|
||
db:
|
||
condition: service_healthy
|
||
entrypoint: ["/app/entrypoint.sh"]
|
||
command: ["/app/server"]
|
||
healthcheck:
|
||
test: ["CMD", "wget", "-q", "--spider", "http://localhost:8082/api/health"]
|
||
interval: 30s
|
||
timeout: 10s
|
||
retries: 3
|
||
start_period: 40s
|
||
|
||
# Frontend (Nginx)
|
||
frontend:
|
||
build:
|
||
context: ./frontend
|
||
dockerfile: Dockerfile
|
||
container_name: wmms-frontend
|
||
restart: unless-stopped
|
||
ports:
|
||
- "80:80"
|
||
depends_on:
|
||
- backend
|
||
|
||
volumes:
|
||
mysql_data:
|
||
uploads_data:
|