feat(docker): set default UV_TOOL_BIN_DIR on docker images (#13391)

Closes #13057

Sets `UV_TOOL_BIN_DIR` to `/usr/local/bin` for all derived images to
allow `uv tool install` to work out of the box.

Note, when the default image user is overwritten (e.g. `USER <UID>`) by
a less privileged one, an alternative writable location would now need
to be set by downstream consumers to prevent issues, hence I'm labeling
this as a breaking change for 0.8.x release.

Relates to https://github.com/astral-sh/uv-docker-example/pull/55

Each image was tested to work with uv tool with `UV_TOOL_BIN_DIR` set to
`/usr/local/bin` with the default root user and alternative non-root
users to confirm breaking nature of the change.
This commit is contained in:
samypr100 2025-06-21 15:42:28 -04:00 committed by Zanie Blue
parent 87e9ccfb92
commit e40357e529
2 changed files with 4 additions and 0 deletions

View file

@ -225,6 +225,7 @@ jobs:
cat <<EOF > Dockerfile cat <<EOF > Dockerfile
FROM ${BASE_IMAGE} FROM ${BASE_IMAGE}
COPY --from=${{ env.UV_GHCR_IMAGE }}:latest /uv /uvx /usr/local/bin/ COPY --from=${{ env.UV_GHCR_IMAGE }}:latest /uv /uvx /usr/local/bin/
ENV UV_TOOL_BIN_DIR="/usr/local/bin"
ENTRYPOINT [] ENTRYPOINT []
CMD ["/usr/local/bin/uv"] CMD ["/usr/local/bin/uv"]
EOF EOF

View file

@ -77,6 +77,9 @@ As with the distroless image, each derived image is published with uv version ta
`ghcr.io/astral-sh/uv:{major}.{minor}.{patch}-{base}` and `ghcr.io/astral-sh/uv:{major}.{minor}.{patch}-{base}` and
`ghcr.io/astral-sh/uv:{major}.{minor}-{base}`, e.g., `ghcr.io/astral-sh/uv:0.7.18-alpine`. `ghcr.io/astral-sh/uv:{major}.{minor}-{base}`, e.g., `ghcr.io/astral-sh/uv:0.7.18-alpine`.
In addition, starting with `0.8` each derived image also sets `UV_TOOL_BIN_DIR` to `/usr/local/bin`
to allow `uv tool install` to work as expected with the default user.
For more details, see the [GitHub Container](https://github.com/astral-sh/uv/pkgs/container/uv) For more details, see the [GitHub Container](https://github.com/astral-sh/uv/pkgs/container/uv)
page. page.