# ============================================================================= # 企微IT智能服务台 — 后端 开发镜像 Dockerfile # ============================================================================= # 与 Dockerfile(prod) 区别: # - 不需要 gcc / libpq-dev(用预编译的 psycopg2-binary) # - 装 pytest 用于跑测试 # - 不需要 multi-stage build(开发用,镜像大一点无所谓) # - 装 watchfiles 配合 uvicorn --reload # ============================================================================= FROM python:3.12-slim LABEL maintainer="IT服务台开发团队" LABEL description="企微IT智能服务台后端 - 开发模式" # 换 apt 源(公司内网,默认 deb.debian.org 可能不通) RUN sed -i "s|deb.debian.org|mirrors.aliyun.com|g" /etc/apt/sources.list.d/debian.sources 2>/dev/null || true; \ sed -i "s|deb.debian.org|mirrors.aliyun.com|g" /etc/apt/sources.list 2>/dev/null || true # 安装运行时依赖(精简版) RUN apt-get update && \ apt-get install -y --no-install-recommends libpq5 curl && \ rm -rf /var/lib/apt/lists/* WORKDIR /app # 换 PyPI 源 + 装依赖 COPY requirements.txt . RUN pip install --no-cache-dir \ --timeout 120 \ --retries 5 \ -i https://pypi.tuna.tsinghua.edu.cn/simple/ \ --trusted-host pypi.tuna.tsinghua.edu.cn \ -r requirements.txt && \ pip install --no-cache-dir \ -i https://pypi.tuna.tsinghua.edu.cn/simple/ \ --trusted-host pypi.tuna.tsinghua.edu.cn \ pytest pytest-asyncio httpx watchfiles # 复制项目代码(在 dev 模式下用 volume mount 覆盖) COPY . . EXPOSE 8000 # 默认命令(在 docker-compose.dev.yml 里覆盖) CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]