docker-compose.yml 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # New-API Docker Compose Configuration
  2. #
  3. # Quick Start:
  4. # 1. docker-compose up -d
  5. # 2. Access at http://localhost:3000
  6. #
  7. # Using MySQL instead of PostgreSQL:
  8. # 1. Comment out the postgres service and SQL_DSN line 29
  9. # 2. Uncomment the mysql service and SQL_DSN line 30
  10. # 3. Uncomment mysql in depends_on (line 46)
  11. # 4. Uncomment mysql_data in volumes section (line 85)
  12. #
  13. # ⚠️ IMPORTANT: Change all default passwords before deploying to production!
  14. services:
  15. new-api:
  16. build:
  17. context: .
  18. dockerfile: Dockerfile
  19. container_name: new-api
  20. restart: always
  21. command: --log-dir /app/logs
  22. ports:
  23. - "3000:3000"
  24. volumes:
  25. - ./data:/data
  26. - ./logs:/app/logs
  27. environment:
  28. # 阿里云 MySQL 连接配置 (Aliyun MySQL Connection)
  29. # 格式: username:password@tcp(host:port)/database
  30. # 示例: - SQL_DSN=root:your_password@tcp(rm-xxxxx.mysql.rds.aliyuncs.com:3306)/new-api
  31. - SQL_DSN=ai_rw:ws8oRahcYm5GwkQy@tcp(mr-y9gker44xqhwnrnv59.rwlb.singapore.rds.aliyuncs.com:3306)/new-api # ⚠️ 请替换为您的阿里云 MySQL 连接信息
  32. # 阿里云 Redis 连接配置 (Aliyun Redis Connection)
  33. # 格式: redis://:password@host:port/db
  34. # 示例: - REDIS_CONN_STRING=redis://:your_password@r-xxxxx.redis.rds.aliyuncs.com:6379/0
  35. - REDIS_CONN_STRING=redis://:RPDUyra6szoS0LA1@r-t4n74k8muxmjo181qd.redis.singapore.rds.aliyuncs.com:6379/0 # ⚠️ 请替换为您的阿里云 Redis 连接信息
  36. - TZ=Asia/Shanghai
  37. - ERROR_LOG_ENABLED=true # 是否启用错误日志记录 (Whether to enable error log recording)
  38. - BATCH_UPDATE_ENABLED=true # 是否启用批量更新 (Whether to enable batch update)
  39. - MAX_REQUEST_BODY_MB=500 # 请求体最大大小(MB),用于支持大文件上传 (Max request body size in MB for large file uploads)
  40. - STREAMING_TIMEOUT=300 # 流模式无响应超时时间,单位秒,默认120秒,如果出现空补全可以尝试改为更大值 (Streaming timeout in seconds, default is 120s. Increase if experiencing empty completions)
  41. # - SESSION_SECRET=random_string # 多机部署时设置,必须修改这个随机字符串!! (multi-node deployment, set this to a random string!!!!!!!)
  42. # - SYNC_FREQUENCY=60 # Uncomment if regular database syncing is needed
  43. # - GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX # Google Analytics 的测量 ID (Google Analytics Measurement ID)
  44. # - UMAMI_WEBSITE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # Umami 网站 ID (Umami Website ID)
  45. # - UMAMI_SCRIPT_URL=https://analytics.umami.is/script.js # Umami 脚本 URL,默认为官方地址 (Umami Script URL, defaults to official URL)
  46. # 使用外部阿里云服务时,不需要依赖本地容器 (No local container dependencies when using external Aliyun services)
  47. # depends_on:
  48. # - redis
  49. # - postgres
  50. healthcheck:
  51. test: ["CMD-SHELL", "wget -q -O - http://localhost:3000/api/status | grep -o '\"success\":\\s*true' || exit 1"]
  52. interval: 30s
  53. timeout: 10s
  54. retries: 3
  55. # ============================================================
  56. # 以下本地服务已禁用,因为使用外部阿里云服务
  57. # Local services disabled - using external Aliyun services
  58. # ============================================================
  59. # redis:
  60. # image: redis:latest
  61. # container_name: redis
  62. # restart: always
  63. #
  64. # postgres:
  65. # image: postgres:15
  66. # container_name: postgres
  67. # restart: always
  68. # environment:
  69. # POSTGRES_USER: root
  70. # POSTGRES_PASSWORD: 123456 # ⚠️ IMPORTANT: Change this password in production!
  71. # POSTGRES_DB: new-api
  72. # volumes:
  73. # - pg_data:/var/lib/postgresql/data
  74. # ports:
  75. # - "5432:5432" # Uncomment if you need to access PostgreSQL from outside Docker
  76. # mysql:
  77. # image: mysql:8.2
  78. # container_name: mysql
  79. # restart: always
  80. # environment:
  81. # MYSQL_ROOT_PASSWORD: 123456 # ⚠️ IMPORTANT: Change this password in production!
  82. # MYSQL_DATABASE: new-api
  83. # volumes:
  84. # - mysql_data:/var/lib/mysql
  85. # ports:
  86. # - "3306:3306" # Uncomment if you need to access MySQL from outside Docker
  87. # 使用外部阿里云服务时不需要本地数据卷 (No local volumes needed when using external Aliyun services)
  88. # volumes:
  89. # pg_data:
  90. # mysql_data: