From c661b218fc690df2554093fb50c3d6e65fde5fd1 Mon Sep 17 00:00:00 2001 From: ata <17314593+asdxzaaaaa@user.noreply.gitee.com> Date: Fri, 10 Jul 2026 10:05:52 +0000 Subject: [PATCH] Add docker-compose.yml --- docker-compose.yml | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..aa6f1cc --- /dev/null +++ b/docker-compose.yml @@ -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: