@ -7,9 +7,7 @@
|
||||
services:
|
||||
# 后端API服务 (仅API服务,无数据库)
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: crpi-b4fqtfbvv583enk2.cn-shanghai.personal.cr.aliyuncs.com/photography-backend/photography:latest
|
||||
container_name: photography-api
|
||||
environment:
|
||||
# 数据库配置 (连接现有服务)
|
||||
|
||||
@ -1,104 +1,53 @@
|
||||
# Photography Portfolio Backend - Docker Compose
|
||||
# 本地开发和测试环境配置
|
||||
# Photography Portfolio Backend - Production Docker Compose
|
||||
# 生产环境配置 - 使用现有 PostgreSQL 和 Redis 服务
|
||||
|
||||
# version 字段已废弃,不再需要使用
|
||||
# version: '3.8'
|
||||
|
||||
services:
|
||||
# PostgreSQL 数据库
|
||||
db:
|
||||
image: postgres:16-alpine
|
||||
container_name: photography-db
|
||||
environment:
|
||||
POSTGRES_DB: photography
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres123
|
||||
POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --lc-collate=C --lc-ctype=C"
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- ./configs/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql:ro
|
||||
networks:
|
||||
- photography-network
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres -d photography"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
# Redis 缓存
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: photography-redis
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
- ./configs/redis.conf:/usr/local/etc/redis/redis.conf:ro
|
||||
command: redis-server /usr/local/etc/redis/redis.conf
|
||||
networks:
|
||||
- photography-network
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 5
|
||||
|
||||
# 后端API服务
|
||||
# 后端API服务 (仅API服务,无数据库)
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: crpi-b4fqtfbvv583enk2.cn-shanghai.personal.cr.aliyuncs.com/photography-backend/photography:latest
|
||||
container_name: photography-api
|
||||
environment:
|
||||
# 数据库配置
|
||||
DB_HOST: db
|
||||
DB_PORT: 5432
|
||||
DB_NAME: photography
|
||||
DB_USER: postgres
|
||||
DB_PASSWORD: postgres123
|
||||
DB_SSL_MODE: disable
|
||||
# 数据库配置 (连接现有服务)
|
||||
DB_HOST: ${DB_HOST:-redis_cache}
|
||||
DB_PORT: ${DB_PORT:-5432}
|
||||
DB_NAME: ${DB_NAME:-photography}
|
||||
DB_USER: ${DB_USER:-postgres}
|
||||
DB_PASSWORD: ${DB_PASSWORD}
|
||||
DB_SSL_MODE: ${DB_SSL_MODE:-disable}
|
||||
|
||||
# Redis配置
|
||||
REDIS_HOST: redis
|
||||
REDIS_PORT: 6379
|
||||
REDIS_PASSWORD: ""
|
||||
REDIS_DB: 0
|
||||
# Redis配置 (连接现有服务)
|
||||
REDIS_HOST: ${REDIS_HOST:-localhost}
|
||||
REDIS_PORT: ${REDIS_PORT:-6379}
|
||||
REDIS_PASSWORD: ${REDIS_PASSWORD:-}
|
||||
REDIS_DB: ${REDIS_DB:-0}
|
||||
|
||||
# JWT配置
|
||||
JWT_SECRET: your-super-secret-jwt-key-change-in-production
|
||||
JWT_EXPIRE: 24h
|
||||
JWT_SECRET: ${JWT_SECRET}
|
||||
JWT_EXPIRE: ${JWT_EXPIRE:-24h}
|
||||
|
||||
# 服务配置
|
||||
APP_ENV: development
|
||||
APP_PORT: 8080
|
||||
APP_HOST: 0.0.0.0
|
||||
APP_ENV: ${APP_ENV:-production}
|
||||
APP_PORT: ${APP_PORT:-8080}
|
||||
APP_HOST: ${APP_HOST:-0.0.0.0}
|
||||
|
||||
# CORS配置
|
||||
CORS_ORIGINS: "http://localhost:3000,http://localhost:3001,http://localhost:5173"
|
||||
CORS_ORIGINS: ${CORS_ORIGINS:-https://photography.iriver.top}
|
||||
|
||||
# 文件上传配置
|
||||
UPLOAD_PATH: /app/uploads
|
||||
UPLOAD_MAX_SIZE: 10485760 # 10MB
|
||||
UPLOAD_PATH: ${UPLOAD_PATH:-/app/uploads}
|
||||
UPLOAD_MAX_SIZE: ${UPLOAD_MAX_SIZE:-10485760}
|
||||
|
||||
# 日志配置
|
||||
LOG_LEVEL: info
|
||||
LOG_FORMAT: json
|
||||
LOG_LEVEL: ${LOG_LEVEL:-info}
|
||||
LOG_FORMAT: ${LOG_FORMAT:-json}
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- uploads_data:/app/uploads
|
||||
- logs_data:/app/logs
|
||||
networks:
|
||||
- photography-network
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "/photography-api", "--health-check"]
|
||||
@ -114,33 +63,17 @@ services:
|
||||
dockerfile: Dockerfile
|
||||
container_name: photography-migrate
|
||||
environment:
|
||||
DB_HOST: db
|
||||
DB_PORT: 5432
|
||||
DB_NAME: photography
|
||||
DB_USER: postgres
|
||||
DB_PASSWORD: postgres123
|
||||
DB_SSL_MODE: disable
|
||||
networks:
|
||||
- photography-network
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
DB_HOST: ${DB_HOST:-localhost}
|
||||
DB_PORT: ${DB_PORT:-5432}
|
||||
DB_NAME: ${DB_NAME:-photography}
|
||||
DB_USER: ${DB_USER:-postgres}
|
||||
DB_PASSWORD: ${DB_PASSWORD}
|
||||
DB_SSL_MODE: ${DB_SSL_MODE:-disable}
|
||||
entrypoint: ["/migrate", "up"]
|
||||
restart: "no"
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
driver: local
|
||||
redis_data:
|
||||
driver: local
|
||||
uploads_data:
|
||||
driver: local
|
||||
logs_data:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
photography-network:
|
||||
driver: bridge
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 172.20.0.0/16
|
||||
driver: local
|
||||
Reference in New Issue
Block a user