docker-compose.yml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. image: calciumion/new-api:latest
  18. container_name: new-api
  19. restart: always
  20. command: --log-dir /app/logs
  21. ports:
  22. - "3000:3000"
  23. volumes:
  24. - ./data:/data
  25. - ./logs:/app/logs
  26. environment:
  27. - SQL_DSN=postgresql://root:123456@postgres:5432/new-api # ⚠️ IMPORTANT: Change the password in production!
  28. # - SQL_DSN=root:123456@tcp(mysql:3306)/new-api # Point to the mysql service, uncomment if using MySQL
  29. - REDIS_CONN_STRING=redis://redis
  30. - TZ=Asia/Shanghai
  31. - ERROR_LOG_ENABLED=true # 是否启用错误日志记录
  32. - BATCH_UPDATE_ENABLED=true # 是否启用批量更新 batch update enabled
  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. depends_on:
  37. - redis
  38. - postgres
  39. # - mysql # Uncomment if using MySQL
  40. healthcheck:
  41. test: ["CMD-SHELL", "wget -q -O - http://localhost:3000/api/status | grep -o '\"success\":\\s*true' || exit 1"]
  42. interval: 30s
  43. timeout: 10s
  44. retries: 3
  45. redis:
  46. image: redis:latest
  47. container_name: redis
  48. restart: always
  49. postgres:
  50. image: postgres:15
  51. container_name: postgres
  52. restart: always
  53. environment:
  54. POSTGRES_USER: root
  55. POSTGRES_PASSWORD: 123456 # ⚠️ IMPORTANT: Change this password in production!
  56. POSTGRES_DB: new-api
  57. volumes:
  58. - pg_data:/var/lib/postgresql/data
  59. # ports:
  60. # - "5432:5432" # Uncomment if you need to access PostgreSQL from outside Docker
  61. # mysql:
  62. # image: mysql:8.2
  63. # container_name: mysql
  64. # restart: always
  65. # environment:
  66. # MYSQL_ROOT_PASSWORD: 123456 # ⚠️ IMPORTANT: Change this password in production!
  67. # MYSQL_DATABASE: new-api
  68. # volumes:
  69. # - mysql_data:/var/lib/mysql
  70. # ports:
  71. # - "3306:3306" # Uncomment if you need to access MySQL from outside Docker
  72. volumes:
  73. pg_data:
  74. # mysql_data: