From dd846876ba41e269cae62e499857b139ceb39920 Mon Sep 17 00:00:00 2001 From: hhs <386998068@qq.com> Date: Sat, 20 Jun 2026 00:26:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=20docker-compose=20?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E6=B3=A8=E5=85=A5=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E4=BF=AE=E5=A4=8D=20postgres/redis=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=AF=BB=E5=8F=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - postgres 和 redis 服务添加 env_file,统一从 /opt/camtalk/.env 读取配置 - 移除 postgres 中多余的 ${POSTGRES_USER/PASSWORD} 透传(env_file 已直接注入) - 移除 backend 中多余的 CAMTALK_STORAGE_DSN 和 CAMTALK_REDIS_PASSWORD 透传 - postgres healthcheck 改用 $$POSTGRES_USER(容器内 shell 变量)替代 ${POSTGRES_USER}(compose 变量替换) - 根本原因:environment 中的 ${VAR} 在 compose 解析时读取 shell 环境,为空时会覆盖 env_file 的值 --- docker-compose.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index fd012f5..74c04bd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,13 +20,11 @@ services: env_file: - /opt/camtalk/.env environment: - # 三级存储配置 + # 三级存储配置(敏感信息通过 env_file 注入) - CAMTALK_STORAGE_REDIS_ENABLED=${CAMTALK_STORAGE_REDIS_ENABLED:-true} - CAMTALK_STORAGE_PERSISTENCE_ENABLED=${CAMTALK_STORAGE_PERSISTENCE_ENABLED:-true} - CAMTALK_STORAGE_PERSISTENCE_DRIVER=${CAMTALK_STORAGE_PERSISTENCE_DRIVER:-postgres} - - CAMTALK_STORAGE_DSN=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/camtalk?sslmode=disable - CAMTALK_REDIS_ADDR=redis:6379 - - CAMTALK_REDIS_PASSWORD=${CAMTALK_REDIS_PASSWORD:-} depends_on: postgres: condition: service_healthy @@ -39,9 +37,9 @@ services: postgres: image: docker.m.daocloud.io/library/postgres:15-alpine container_name: camtalk-postgres + env_file: + - /opt/camtalk/.env environment: - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: camtalk volumes: - pgdata:/var/lib/postgresql/data @@ -49,7 +47,7 @@ services: networks: - camtalk-net healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d camtalk"] + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d camtalk"] interval: 5s timeout: 3s retries: 10 @@ -58,6 +56,8 @@ services: redis: image: docker.m.daocloud.io/library/redis:7-alpine container_name: camtalk-redis + env_file: + - /opt/camtalk/.env command: > sh -c ' if [ -n "$$CAMTALK_REDIS_PASSWORD" ]; then @@ -65,8 +65,6 @@ services: else exec redis-server --appendonly yes fi' - environment: - CAMTALK_REDIS_PASSWORD: ${CAMTALK_REDIS_PASSWORD:-} volumes: - redisdata:/data networks: -- 2.49.1