# ============================================================================== # 上海炫恒网络系统有限公司 官网 —— Docker Compose 部署 # # 用法: # docker compose up -d --build 构建并后台启动 # docker compose logs -f 查看日志 # docker compose ps 查看健康状态 # docker compose down 停止并删除容器 # # 改端口:在项目根目录建 .env 文件,写入 SITE_PORT=80 # (默认 8080,即 http://localhost:8080) # ============================================================================== services: web: build: context: . dockerfile: Dockerfile image: xuanheng-website:latest container_name: xuanheng-web # 宿主机端口 : 容器端口(容器内 nginx 固定监听 80) # 想用 80 端口:把下面改成 "80:80",或建 .env 写 SITE_PORT=80 ports: - "${SITE_PORT:-8080}:80" restart: unless-stopped environment: - TZ=Asia/Shanghai # 与 Dockerfile 里的 HEALTHCHECK 一致,写在这里便于查看 healthcheck: test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1/healthz"] interval: 30s timeout: 3s retries: 3 start_period: 5s # 纯静态站点不需要额外权限,收紧容器权限 security_opt: - no-new-privileges:true # 限制日志体积,避免长期运行把磁盘写满 logging: driver: json-file options: max-size: "10m" max-file: "3"