Files
CamTalk/docker-compose.yml
hhs dd846876ba fix: 统一 docker-compose 环境变量注入方式,修复 postgres/redis 配置读取问题
- 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 的值
2026-06-20 00:26:03 +08:00

86 lines
2.2 KiB
YAML

services:
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: camtalk-frontend
ports:
- "9000:80"
depends_on:
- backend
networks:
- camtalk-net
restart: unless-stopped
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: camtalk-backend
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_REDIS_ADDR=redis:6379
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
networks:
- camtalk-net
restart: unless-stopped
postgres:
image: docker.m.daocloud.io/library/postgres:15-alpine
container_name: camtalk-postgres
env_file:
- /opt/camtalk/.env
environment:
POSTGRES_DB: camtalk
volumes:
- pgdata:/var/lib/postgresql/data
- ./backend/migrations:/docker-entrypoint-initdb.d
networks:
- camtalk-net
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d camtalk"]
interval: 5s
timeout: 3s
retries: 10
restart: unless-stopped
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
exec redis-server --appendonly yes --requirepass "$$CAMTALK_REDIS_PASSWORD"
else
exec redis-server --appendonly yes
fi'
volumes:
- redisdata:/data
networks:
- camtalk-net
healthcheck:
test: ["CMD-SHELL", "if [ -n \"$$CAMTALK_REDIS_PASSWORD\" ]; then redis-cli -a \"$$CAMTALK_REDIS_PASSWORD\" ping; else redis-cli ping; fi"]
interval: 5s
timeout: 3s
retries: 10
restart: unless-stopped
volumes:
pgdata:
redisdata:
networks:
camtalk-net:
driver: bridge