Spaces:
Running
Running
File size: 902 Bytes
b7bd3ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# 使用Python 3.11作为基础镜像
FROM python:3.11-slim
# 设置工作目录
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# 安装依赖,包括 git 和 redis-server
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
redis-server \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# 复制并安装 Python 依赖
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# 复制应用代码和启动脚本
COPY . .
COPY start.sh .
RUN chmod +x start.sh # 赋予脚本执行权限
# 创建非 root 用户,并赋予 /app 目录和脚本权限
RUN adduser --disabled-password --gecos "" appuser \
&& chown -R appuser:appuser /app \
&& chown appuser:appuser start.sh
# 切换到非 root 用户
USER appuser
# 暴露端口
EXPOSE 7860
# 使用启动脚本启动 Redis 和 Python 应用
CMD ["./start.sh"]
|