# 使用官方镜像 FROM calciumion/new-api:latest # 设置时区(必须) ENV TZ=Asia/Shanghai # 使用 Alpine 包管理器安装 nginx RUN apk add --no-cache nginx # 创建 nginx 配置 RUN echo 'events { worker_connections 1024; } \ http { \ server { \ listen 7860; \ location / { \ proxy_pass http://127.0.0.1:3000; \ proxy_set_header Host $host; \ proxy_set_header X-Real-IP $remote_addr; \ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \ } \ } \ }' > /etc/nginx/nginx.conf # 创建数据目录并设置权限(关键修复) RUN mkdir -p /data && \ chmod 777 /data && \ mkdir -p /data/logs && \ chmod 777 /data/logs # 创建 .env 文件(消除警告) RUN echo "# Hugging Face Spaces Environment Variables" > /.env # 创建启动脚本(修复权限问题) RUN echo '#!/bin/sh \ # 确保数据目录权限(挂载后可能被重置) \ chmod 777 /data \ chmod 777 /data/logs \ # 启动 nginx(后台运行) \ nginx & \ # 启动 NewAPI(前台运行) \ exec /app/docker-entrypoint.sh' > /start.sh && \ chmod +x /start.sh # 暴露端口 EXPOSE 7860 # 设置数据卷(Spaces 会自动挂载) # VOLUME /data # 启动命令 CMD ["/start.sh"]