Created
May 18, 2025 13:19
-
-
Save Imyukehan/81c9177ad8b20cecfa6db4ee447e9c61 to your computer and use it in GitHub Desktop.
UV 项目标准dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 使用官方推荐的 Python 基础镜像 | |
FROM python:3.12-slim AS builder | |
# 安装 uv(推荐直接用官方 distroless 镜像复制二进制文件,速度快且干净) | |
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ | |
WORKDIR /app | |
# 先复制依赖文件,利用 Docker 层缓存 | |
COPY pyproject.toml uv.lock ./ | |
# 安装依赖(不安装项目本身,加快后续构建) | |
RUN --mount=type=cache,target=/root/.cache/uv \ | |
uv sync --locked --no-install-project | |
# 再复制项目代码 | |
COPY . . | |
# 安装项目本身 | |
RUN --mount=type=cache,target=/root/.cache/uv \ | |
uv sync --locked | |
EXPOSE 8000 | |
CMD ["uv", "run", "uvicorn", "app.main:app"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment