diff --git a/Dockerfile.api b/Dockerfile.api index 814f30d..2813512 100644 --- a/Dockerfile.api +++ b/Dockerfile.api @@ -67,15 +67,18 @@ COPY migrations /app/migrations COPY docker/entrypoint-api.sh /app/entrypoint.sh RUN chmod +x /app/entrypoint.sh +# 创建日志目录并设置权限(在切换用户前) +RUN mkdir -p /app/logs && chown -R appuser:appuser /app/logs + # 切换到非 root 用户 USER appuser # 暴露端口 EXPOSE 3000 -# 健康检查(使用 Alpine 自带的 wget) +# 健康检查(使用 127.0.0.1 强制 IPv4,避免 IPv6 连接问题) HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ - CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1 + CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:3000/health || exit 1 # 启动命令 ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/cmd/api/main.go b/cmd/api/main.go index 94fea28..aa181b9 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -81,7 +81,7 @@ func main() { initRoutes(app, cfg, result, queueClient, db, redisClient, appLogger) // 12. 生成 OpenAPI 文档 - generateOpenAPIDocs("./openapi.yaml", appLogger) + generateOpenAPIDocs("logs/openapi.yaml", appLogger) // 13. 启动服务器 startServer(app, cfg, appLogger, cancelWatch) diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index bc9ff17..914d75c 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -20,7 +20,7 @@ services: networks: - junhong-network healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/health"] + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3000/health"] interval: 30s timeout: 3s retries: 3