From aaf887507fcfa98d9a1b0b2c4cff8c3094408835 Mon Sep 17 00:00:00 2001 From: chenjw28 <792430652@qq.com> Date: Sat, 26 Sep 2026 20:58:10 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(deploy):=20backend=20?= =?UTF-8?q?=E5=AE=BF=E4=B8=BB=E6=9C=BA=E7=AB=AF=E5=8F=A3=E5=8F=97=20.env?= =?UTF-8?q?=20BACKEND=5FPORT=20=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一版 backend 写死 expose: ["8000"](不暴露宿主),但这违背"全局服 务的最终映射到宿主机只能受 .env 中的端口配置决定"的原则——调试场景下 .env 没办法把 backend 暴露到宿主。 修正:backend ports 改为 "${BACKEND_PORT:-}:8000",由 .env 决定: - BACKEND_PORT 留空/未设 = 不暴露宿主端口(仅经前端 /api 反代) - BACKEND_PORT=10003 = 暴露宿主 10003(调试 / 压测用) .env.example 同步加注释说明。 验证:模拟 .env 两种场景下,端口映射完全由 BACKEND_PORT 决定。 Co-Authored-By: Claude Code --- .env.example | 3 +++ docker-compose.yml | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index b95cd91..7f56b27 100644 --- a/.env.example +++ b/.env.example @@ -11,6 +11,9 @@ FRONTEND_PORT=10003 MOLDINSIGHT_PORT=10003 # inventory-only 独立部署时使用 INVENTORY_PORT=10004 +# unified 模式 backend 是否暴露宿主端口:留空 = 不暴露(仅经前端 /api 反代), +# 设值(如 10003)= 直接暴露(调试 / 压测用) +# BACKEND_PORT= # ================================ DEBUG=false diff --git a/docker-compose.yml b/docker-compose.yml index 4d11558..c567dde 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -76,10 +76,11 @@ services: image: gemold-backend:latest container_name: gemold_backend command: ["python", "-m", "uvicorn", "entrypoints.unified:app", "--host", "0.0.0.0", "--port", "8000"] - # 不映射端口到宿主机:backend 仅供 frontend 反代(docker 网络内 backend:8000 互通), - # 避免与 frontend 抢占宿主 10003。BACKEND_PORT 仍保留以便调试时临时开放。 - expose: - - "8000" + # 宿主机端口由 .env 的 BACKEND_PORT 决定:空/不设则不暴露宿主机端口 + # (仅经前端 /api 反代同域访问,避免与 frontend 抢占宿主 10003)。 + # 调试时设 BACKEND_PORT=10003 即可独立访问。 + ports: + - "${BACKEND_PORT:-}:8000" environment: <<: *base_env ADMIN_USERNAME: ${ADMIN_USERNAME:-admin}