Update Dockerfile
Browse files- Dockerfile +20 -11
Dockerfile
CHANGED
|
@@ -1,36 +1,42 @@
|
|
|
|
|
|
|
|
| 1 |
FROM rfym21/qwen2api:latest
|
| 2 |
|
| 3 |
-
# 切换到 root 用户进行安装
|
| 4 |
USER root
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
# 配置 Supervisor 来管理 Redis 和你的原始应用
|
| 13 |
# 1. 创建 supervisor 配置文件目录 (如果不存在)
|
| 14 |
RUN mkdir -p /etc/supervisor/conf.d/
|
| 15 |
|
| 16 |
# 2. 创建 supervisor 配置文件
|
|
|
|
|
|
|
| 17 |
COPY <<EOF /etc/supervisor/conf.d/supervisord.conf
|
| 18 |
[supervisord]
|
| 19 |
nodaemon=true ; 在前台运行 supervisord
|
| 20 |
user=root ; 以 root 运行 supervisord (需要管理其他进程)
|
| 21 |
|
| 22 |
[program:redis]
|
| 23 |
-
command=/usr/bin/redis-server --loglevel warning ; 启动 redis server
|
| 24 |
autostart=true
|
| 25 |
autorestart=true
|
| 26 |
stderr_logfile=/dev/stderr ; 将 stderr 重定向到容器日志
|
| 27 |
stderr_logfile_maxbytes=0
|
| 28 |
stdout_logfile=/dev/stdout ; 将 stdout 重定向到容器日志
|
| 29 |
stdout_logfile_maxbytes=0
|
| 30 |
-
user=redis ;
|
| 31 |
-
; 如果不行,可能需要以 root 运行或调整目录权限
|
| 32 |
|
| 33 |
[program:qwen2api]
|
|
|
|
|
|
|
|
|
|
| 34 |
command=npm start --arg1 --arg2
|
| 35 |
autostart=true
|
| 36 |
autorestart=true
|
|
@@ -44,8 +50,11 @@ stdout_logfile_maxbytes=0
|
|
| 44 |
EOF
|
| 45 |
|
| 46 |
# 设置环境变量 REDIS_URL
|
| 47 |
-
# 因为 Redis 和应用在同一个容器内,使用 localhost
|
| 48 |
ENV REDIS_URL=redis://localhost:6379/0
|
| 49 |
|
|
|
|
|
|
|
|
|
|
| 50 |
# 容器启动时运行 Supervisor,它会负责启动 Redis 和你的应用
|
|
|
|
| 51 |
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
|
|
|
| 1 |
+
# 警告:仍然不推荐在单一容器中运行多个服务
|
| 2 |
+
|
| 3 |
FROM rfym21/qwen2api:latest
|
| 4 |
|
| 5 |
+
# 切换到 root 用户进行安装 (apk 通常需要 root 权限)
|
| 6 |
USER root
|
| 7 |
|
| 8 |
+
# 使用 Alpine 的包管理器 'apk' 来安装 Redis 和 Supervisor
|
| 9 |
+
# '--no-cache' 选项可以在一次命令中完成添加和清理缓存,保持镜像层较小
|
| 10 |
+
RUN apk update && \
|
| 11 |
+
apk add --no-cache redis supervisor
|
| 12 |
+
|
| 13 |
+
# --- 接下来的 Supervisor 配置部分保持不变 ---
|
| 14 |
|
|
|
|
| 15 |
# 1. 创建 supervisor 配置文件目录 (如果不存在)
|
| 16 |
RUN mkdir -p /etc/supervisor/conf.d/
|
| 17 |
|
| 18 |
# 2. 创建 supervisor 配置文件
|
| 19 |
+
# 注意:你仍然需要知道原始镜像 'rfym21/qwen2api:latest' 的启动命令!
|
| 20 |
+
# 将下面的 'your_original_app_command_here' 替换为实际命令。
|
| 21 |
COPY <<EOF /etc/supervisor/conf.d/supervisord.conf
|
| 22 |
[supervisord]
|
| 23 |
nodaemon=true ; 在前台运行 supervisord
|
| 24 |
user=root ; 以 root 运行 supervisord (需要管理其他进程)
|
| 25 |
|
| 26 |
[program:redis]
|
| 27 |
+
command=/usr/bin/redis-server --loglevel warning ; 启动 redis server (检查路径是否正确,Alpine中通常在此)
|
| 28 |
autostart=true
|
| 29 |
autorestart=true
|
| 30 |
stderr_logfile=/dev/stderr ; 将 stderr 重定向到容器日志
|
| 31 |
stderr_logfile_maxbytes=0
|
| 32 |
stdout_logfile=/dev/stdout ; 将 stdout 重定向到容器日志
|
| 33 |
stdout_logfile_maxbytes=0
|
| 34 |
+
# user=redis ; Alpine 默认可能没有 'redis' 用户,可能需要以 root 运行或创建用户
|
|
|
|
| 35 |
|
| 36 |
[program:qwen2api]
|
| 37 |
+
# !!! 重要: 将 'your_original_app_command_here --arg1 --arg2' 替换为基础镜像的实际启动命令 !!!
|
| 38 |
+
# 例如: command=python /app/main.py --host 0.0.0.0
|
| 39 |
+
# 如果原始镜像是通过 ENTRYPOINT 执行脚本,你可能需要调用那个脚本
|
| 40 |
command=npm start --arg1 --arg2
|
| 41 |
autostart=true
|
| 42 |
autorestart=true
|
|
|
|
| 50 |
EOF
|
| 51 |
|
| 52 |
# 设置环境变量 REDIS_URL
|
|
|
|
| 53 |
ENV REDIS_URL=redis://localhost:6379/0
|
| 54 |
|
| 55 |
+
# (可选) 切换回非 root 用户 (如果原始镜像或应用需要)
|
| 56 |
+
# USER your_app_user
|
| 57 |
+
|
| 58 |
# 容器启动时运行 Supervisor,它会负责启动 Redis 和你的应用
|
| 59 |
+
# 检查 supervisord 的路径在 Alpine 中是否正确,通常是 /usr/bin/supervisord
|
| 60 |
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|