docker-compose.yml 4.9 KB

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