Using uv in Docker
https://docs.astral.sh/uv/guides/integration/docker/
#uv #Dockerfile
ghcr.io/astral-sh/uv
(https://github.com/astral-sh/uv/pkgs/container/uv から確認できる)
Getting started
uv sync --frozen
Sync the project into a new environment, using the frozen lockfile
It is best practice to add .venv to a .dockerignore file in your repository to prevent it from being included in image builds.
PATH または uv run
Developing in a container
積ん読
Optimizations
Compiling bytecode
Caching
RUN --mount=type=cache,target=/root/.cache/uv
2024年版のDockerfileの考え方&書き方
Intermediate layers
続く例のように2段にする(依存のインストール -> プロジェクトのインストール)
Non-editable installs
uv sync --no-editable (0.4.11~)
Using uv temporarily
RUN --mount=from=ghcr.io/astral-sh/uv,source=/uv,target=/bin/uv uv sync
Using the pip interface
UV_SYSTEM_PYTHON
uv pip install --system (Python's UV tool is actually pretty good)
uvプロジェクトは2段で入れるように案内
例:https://github.com/astral-sh/uv-docker-example/blob/main/Dockerfile
UV_COMPILE_BYTECODE
UV_LINK_MODE
Copy from the cache instead of linking since it's a mounted volume
コメントの通り、即時copyしてしまうのがよい
Install the project's dependencies using the lockfile and settings
uv sync --frozen --no-install-project --no-dev
Then, add the rest of the project source code and install it
uv sync --frozen --no-dev
=ライブラリのeditable install
PATHに.venvを追加
ghcr.io/astral-sh/uvのENTRYPOINTを[]で上書き
Reset the entrypoint, don't invoke uv