# 基础镜像:uv python3.12 轻量版 FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim # 1. 安装 git 并清理 apt 缓存,减少镜像体积 RUN apt-get update && \ apt-get install -y --no-install-recommends git && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* # 2. 克隆代码到 /app 目录(自动创建 /app,无需手动mkdir) RUN git clone https://github.com/erxiansheng/gemininixiang.git /app # 3. 创建缓存目录,使用合理权限(避免 777 宽松权限) RUN mkdir /.cache && chmod -R 777 /.cache # 5. 切换工作目录 WORKDIR /app # 6. 暴露端口 EXPOSE 8000 # 7. 使用 uv 安装依赖(适配基础镜像,替代 pip) # --no-cache-dir 进一步减少缓存文件,缩小镜像体积 RUN uv venv && \ . .venv/bin/activate && \ uv pip install --no-cache-dir -r requirements.txt # 启动时先激活虚拟环境,再运行应用 CMD ["/bin/sh", "-c", ". .venv/bin/activate && python server.py"]