docker-compose.yml 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 13
  9. # 2. Uncomment the mysql service and SQL_DSN line 14
  10. # 3. Uncomment mysql in depends_on (line 26)
  11. # 4. Uncomment mysql_data in volumes section (line 62)
  12. #
  13. # ⚠️ IMPORTANT: Change all default passwords before deploying to production!
  14. services:
  15. new-api:
  16. image: calciumion/new-api:latest
  17. container_name: new-api
  18. restart: always
  19. command: --log-dir /app/logs
  20. ports:
  21. - "3000:3000"
  22. volumes:
  23. - ./data:/data
  24. - ./logs:/app/logs
  25. environment:
  26. - SQL_DSN=postgresql://root:123456@postgres:5432/new-api # ⚠️ IMPORTANT: Change the password in production!
  27. # - SQL_DSN=root:123456@tcp(mysql:3306)/new-api # Point to the mysql service, uncomment if using MySQL
  28. - REDIS_CONN_STRING=redis://redis
  29. - TZ=Asia/Shanghai
  30. - ERROR_LOG_ENABLED=true # 是否启用错误日志记录 (Whether to enable error log recording)
  31. - BATCH_UPDATE_ENABLED=true # 是否启用批量更新 (Whether to enable batch update)
  32. - MAX_REQUEST_BODY_MB=500 # 请求体最大大小(MB),用于支持大文件上传 (Max request body size in MB for large file uploads)
  33. - STREAMING_TIMEOUT=300 # 流模式无响应超时时间,单位秒,默认120秒,如果出现空补全可以尝试改为更大值 (Streaming timeout in seconds, default is 120s. Increase if experiencing empty completions)
  34. # - SESSION_SECRET=random_string # 多机部署时设置,必须修改这个随机字符串!! (multi-node deployment, set this to a random string!!!!!!!)
  35. # - SYNC_FREQUENCY=60 # Uncomment if regular database syncing is needed
  36. # - GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX # Google Analytics 的测量 ID (Google Analytics Measurement ID)
  37. # - UMAMI_WEBSITE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # Umami 网站 ID (Umami Website ID)
  38. # - UMAMI_SCRIPT_URL=https://analytics.umami.is/script.js # Umami 脚本 URL,默认为官方地址 (Umami Script URL, defaults to official URL)
  39. depends_on:
  40. - redis
  41. - postgres
  42. # - mysql # Uncomment if using MySQL
  43. healthcheck:
  44. test: ["CMD-SHELL", "wget -q -O - http://localhost:3000/api/status | grep -o '\"success\":\\s*true' || exit 1"]
  45. interval: 30s
  46. timeout: 10s
  47. retries: 3
  48. redis:
  49. image: redis:latest
  50. container_name: redis
  51. restart: always
  52. postgres:
  53. image: postgres:15
  54. container_name: postgres
  55. restart: always
  56. environment:
  57. POSTGRES_USER: root
  58. POSTGRES_PASSWORD: 123456 # ⚠️ IMPORTANT: Change this password in production!
  59. POSTGRES_DB: new-api
  60. volumes:
  61. - pg_data:/var/lib/postgresql/data
  62. # ports:
  63. # - "5432:5432" # Uncomment if you need to access PostgreSQL from outside Docker
  64. # mysql:
  65. # image: mysql:8.2
  66. # container_name: mysql
  67. # restart: always
  68. # environment:
  69. # MYSQL_ROOT_PASSWORD: 123456 # ⚠️ IMPORTANT: Change this password in production!
  70. # MYSQL_DATABASE: new-api
  71. # volumes:
  72. # - mysql_data:/var/lib/mysql
  73. # ports:
  74. # - "3306:3306" # Uncomment if you need to access MySQL from outside Docker
  75. volumes:
  76. pg_data:
  77. # mysql_data: