Add docker-compose.yml

This commit is contained in:
ata
2026-07-10 10:05:52 +00:00
committed by Gitee
parent f2353c4f28
commit c661b218fc

76
docker-compose.yml Normal file
View File

@@ -0,0 +1,76 @@
# ============================================
# docker-compose.yml — gotest 生产部署编排
# 用法:docker-compose up -d
# ============================================
version: "3.8"
services:
# ---- Go 应用服务 ----
gotest:
build:
context: .
dockerfile: Dockerfile
container_name: gotest
ports:
- "8080:8080"
volumes:
# 持久化 SQLite 数据库
- ./data:/app/data
# 持久化上传文件
- ./uploads:/app/uploads
# 配置文件(可覆盖镜像内置配置)
- ./config.yaml:/app/config.yaml:ro
environment:
- TZ=Asia/Shanghai
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "-q", "-O-", "http://localhost:8080/api/health"]
interval: 30s
timeout: 5s
start_period: 10s
retries: 3
depends_on:
redis:
condition: service_healthy
# ---- Redis 缓存(预留,应用代码中可按需接入) ----
redis:
image: redis:7-alpine
container_name: gotest-redis
ports:
- "6379:6379"
volumes:
- redis-data:/data
command: redis-server --maxmemory 256mb --maxmemory-policy allkeys-lru
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 3
# ---- MySQL(可选:高并发场景切换数据库驱动) ----
# 取消注释即可启用 MySQL,然后在 config.yaml 中设置 driver: mysql
# mysql:
# image: mysql:8.0
# container_name: gotest-mysql
# ports:
# - "3306:3306"
# environment:
# MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root123}
# MYSQL_DATABASE: gotest
# MYSQL_USER: gotest
# MYSQL_PASSWORD: ${MYSQL_PASSWORD:-gotest123}
# volumes:
# - mysql-data:/var/lib/mysql
# restart: unless-stopped
# healthcheck:
# test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
# interval: 10s
# timeout: 5s
# retries: 3
volumes:
redis-data:
# mysql-data: