# Houses 全套服务:docker compose --env-file deploy/.env.production up -d --build # web 只监听本机端口,对外 HTTPS 由宿主机的 Caddy / nginx 反向代理到 127.0.0.1:${WEB_PORT}。 # 数据目录默认用 Docker 命名卷;服务器上可通过 *_DIR 变量改成系统盘上的目录(见 deploy/.env.production.example)。 name: houses services: postgres: image: postgres:16-alpine restart: unless-stopped # 小内存服务器友好:房源与账单数据量不大,够用即可 command: ["postgres", "-c", "shared_buffers=64MB", "-c", "max_connections=40", "-c", "effective_cache_size=256MB"] environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DATABASE} volumes: - ${PG_DATA_DIR:-pgdata}:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DATABASE}"] interval: 10s timeout: 5s retries: 10 redis: image: redis:7-alpine restart: unless-stopped command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}", "--appendonly", "yes", "--maxmemory", "64mb", "--maxmemory-policy", "allkeys-lru"] volumes: - ${REDIS_DATA_DIR:-redisdata}:/data healthcheck: test: ["CMD-SHELL", "redis-cli -a \"$${REDIS_PASSWORD}\" ping | grep PONG"] interval: 10s timeout: 5s retries: 10 environment: REDIS_PASSWORD: ${REDIS_PASSWORD} api: image: houses-api:${HOUSES_VERSION:-latest} build: context: ./backend restart: unless-stopped env_file: ${HOUSES_ENV_FILE:-deploy/.env.production} environment: POSTGRES_HOST: postgres POSTGRES_PORT: "5432" REDIS_HOST: redis REDIS_PORT: "6379" UPLOAD_DIR: /data/uploads volumes: - ${UPLOADS_DIR:-uploads}:/data/uploads # 首次启动要执行数据库迁移,小内存服务器上可能超过 1 分钟;给足启动宽限,避免 web 因依赖判定失败而没起来 healthcheck: test: ["CMD", "python", "-c", "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8020/api/health', timeout=4).status == 200 else 1)"] interval: 15s timeout: 5s retries: 5 start_period: 120s depends_on: postgres: condition: service_healthy redis: condition: service_healthy web: image: houses-web:${HOUSES_VERSION:-latest} build: context: ./frontend restart: unless-stopped ports: - "127.0.0.1:${WEB_PORT:-8080}:80" environment: # 高德 JS API 安全密钥,只在 nginx 代理里使用(Key 本身由 api 的 AMAP_KEY 下发) AMAP_SECURITY_CODE: ${AMAP_SECURITY_CODE:-} volumes: - ${UPLOADS_DIR:-uploads}:/data/uploads:ro depends_on: api: condition: service_healthy volumes: pgdata: redisdata: uploads: