2025-10-02 16:14:15 +08:00
# New-API Docker Compose Configuration
#
# Quick Start:
# 1. docker-compose up -d
# 2. Access at http://localhost:3000
#
# Using MySQL instead of PostgreSQL:
# 1. Comment out the postgres service and SQL_DSN line 15
# 2. Uncomment the mysql service and SQL_DSN line 16
# 3. Uncomment mysql in depends_on (line 28)
# 4. Uncomment mysql_data in volumes section (line 64)
#
# ⚠️ IMPORTANT: Change all default passwords before deploying to production!
2025-10-02 16:20:15 +08:00
version : '3.4' # For compatibility with older Docker versions
2023-05-11 16:56:14 +08:00
services :
2023-12-16 21:26:05 +08:00
new-api :
2024-03-02 19:58:36 +08:00
image : calciumion/new-api:latest
2023-12-16 21:26:05 +08:00
container_name : new-api
2023-05-11 16:56:14 +08:00
restart : always
command : --log-dir /app/logs
ports :
- "3000:3000"
volumes :
2023-05-31 15:37:59 +08:00
- ./data:/data
- ./logs:/app/logs
2023-06-22 11:15:01 +08:00
environment :
2025-10-02 16:14:15 +08:00
- SQL_DSN=postgresql://root:123456@postgres:5432/new-api # ⚠️ IMPORTANT : Change the password in production!
# - SQL_DSN=root:123456@tcp(mysql:3306)/new-api # Point to the mysql service, uncomment if using MySQL
2026-04-18 00:56:07 +08:00
- REDIS_CONN_STRING=redis://:123456@redis:6379 # ⚠️ IMPORTANT : Change the password in production!
2023-06-22 11:15:01 +08:00
- TZ=Asia/Shanghai
2025-10-14 14:19:49 +08:00
- ERROR_LOG_ENABLED=true # 是否启用错误日志记录 (Whether to enable error log recording)
- BATCH_UPDATE_ENABLED=true # 是否启用批量更新 (Whether to enable batch update)
2026-04-18 00:51:04 +08:00
- NODE_NAME=new-api-node-1 # 节点名称,用于审计日志中标识节点身份;多节点/容器部署时建议设置 (Node name used in audit logs; recommended when running multiple instances or in containers)
2025-10-14 14:19:49 +08:00
# - STREAMING_TIMEOUT=300 # 流模式无响应超时时间, 单位秒, 默认120秒, 如果出现空补全可以尝试改为更大值 ( Streaming timeout in seconds, default is 120s. Increase if experiencing empty completions)
# - SESSION_SECRET=random_string # 多机部署时设置,必须修改这个随机字符串!! ( multi-node deployment, set this to a random string!!!!!!!)
2025-10-02 16:14:15 +08:00
# - SYNC_FREQUENCY=60 # Uncomment if regular database syncing is needed
2025-10-14 14:19:49 +08:00
# - GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX # Google Analytics 的测量 ID (Google Analytics Measurement ID)
# - UMAMI_WEBSITE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # Umami 网站 ID (Umami Website ID)
# - UMAMI_SCRIPT_URL=https://analytics.umami.is/script.js # Umami 脚本 URL, 默认为官方地址 (Umami Script URL, defaults to official URL)
2023-06-22 20:39:17 +08:00
2023-06-22 14:49:33 +08:00
depends_on :
- redis
2025-10-02 16:14:15 +08:00
- postgres
# - mysql # Uncomment if using MySQL
2026-03-06 15:44:47 +08:00
networks :
- new-api-network
2023-05-11 16:56:14 +08:00
healthcheck :
2025-10-02 16:14:15 +08:00
test : [ "CMD-SHELL" , "wget -q -O - http://localhost:3000/api/status | grep -o '\"success\":\\s*true' || exit 1" ]
2023-05-11 16:56:14 +08:00
interval : 30s
timeout : 10s
retries : 3
2023-06-22 11:15:01 +08:00
redis :
image : redis:latest
container_name : redis
restart : always
2026-04-18 00:56:07 +08:00
command : [ "redis-server" , "--requirepass" , "123456" ] # ⚠️ IMPORTANT : Change this password in production!
2026-03-06 15:44:47 +08:00
networks :
- new-api-network
2024-11-23 16:26:30 +08:00
2025-10-02 16:14:15 +08:00
postgres :
image : postgres:15
container_name : postgres
2024-11-23 16:26:30 +08:00
restart : always
environment :
2025-10-02 16:14:15 +08:00
POSTGRES_USER : root
POSTGRES_PASSWORD: 123456 # ⚠️ IMPORTANT : Change this password in production!
POSTGRES_DB : new-api
2024-11-23 16:26:30 +08:00
volumes :
2025-10-02 16:14:15 +08:00
- pg_data:/var/lib/postgresql/data
2026-03-06 15:44:47 +08:00
networks :
- new-api-network
2025-10-02 16:14:15 +08:00
# ports:
# - "5432:5432" # Uncomment if you need to access PostgreSQL from outside Docker
# mysql:
# image: mysql:8.2
# container_name: mysql
# restart: always
# environment:
# MYSQL_ROOT_PASSWORD: 123456 # ⚠️ IMPORTANT: Change this password in production!
# MYSQL_DATABASE: new-api
# volumes:
# - mysql_data:/var/lib/mysql
2026-03-06 15:44:47 +08:00
# networks:
# - new-api-network
2025-10-02 16:14:15 +08:00
# ports:
# - "3306:3306" # Uncomment if you need to access MySQL from outside Docker
2024-11-23 16:26:30 +08:00
volumes :
2025-10-02 16:14:15 +08:00
pg_data :
# mysql_data:
2026-03-06 15:44:47 +08:00
networks :
new-api-network :
driver : bridge