q2a-1 / Dockerfile
krin002's picture
Update Dockerfile
8b9babc verified
# 警告:仍然不推荐在单一容器中运行多个服务
FROM rfym21/qwen2api:latest
# 切换到 root 用户进行安装 (apk 通常需要 root 权限)
USER root
# 使用 Alpine 的包管理器 'apk' 来安装 Redis 和 Supervisor
# '--no-cache' 选项可以在一次命令中完成添加和清理缓存,保持镜像层较小
RUN apk update && \
apk add --no-cache redis supervisor
# --- 接下来的 Supervisor 配置部分保持不变 ---
# 1. 创建 supervisor 配置文件目录 (如果不存在)
RUN mkdir -p /etc/supervisor/conf.d/
# 2. 创建 supervisor 配置文件
# 注意:你仍然需要知道原始镜像 'rfym21/qwen2api:latest' 的启动命令!
# 将下面的 'your_original_app_command_here' 替换为实际命令。
COPY <<EOF /etc/supervisor/conf.d/supervisord.conf
[supervisord]
nodaemon=true ; 在前台运行 supervisord
user=root ; 以 root 运行 supervisord (需要管理其他进程)
[program:redis]
command=/usr/bin/redis-server --loglevel warning ; 启动 redis server (检查路径是否正确,Alpine中通常在此)
autostart=true
autorestart=true
stderr_logfile=/dev/stderr ; 将 stderr 重定向到容器日志
stderr_logfile_maxbytes=0
stdout_logfile=/dev/stdout ; 将 stdout 重定向到容器日志
stdout_logfile_maxbytes=0
# user=redis ; Alpine 默认可能没有 'redis' 用户,可能需要以 root 运行或创建用户
[program:qwen2api]
# !!! 重要: 将 'your_original_app_command_here --arg1 --arg2' 替换为基础镜像的实际启动命令 !!!
# 例如: command=python /app/main.py --host 0.0.0.0
# 如果原始镜像是通过 ENTRYPOINT 执行脚本,你可能需要调用那个脚本
command=npm start --arg1 --arg2
autostart=true
autorestart=true
stopwaitsecs=10 ; 等待10秒优雅停止
stderr_logfile=/dev/stderr ; 将 stderr 重定向到容器日志
stderr_logfile_maxbytes=0
stdout_logfile=/dev/stdout ; 将 stdout 重定向到容器日志
stdout_logfile_maxbytes=0
# user=... ; 如果原始应用需要以特定用户运行,在这里指定
# directory=/app ; 如果应用需要特定的工作目录,在这里指定
EOF
# 设置环境变量 REDIS_URL
ENV REDIS_URL=redis://localhost:6379/0
# (可选) 切换回非 root 用户 (如果原始镜像或应用需要)
# USER your_app_user
# 容器启动时运行 Supervisor,它会负责启动 Redis 和你的应用
# 检查 supervisord 的路径在 Alpine 中是否正确,通常是 /usr/bin/supervisord
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]