astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
28.42k stars 808 forks source link

Can't use uv docker image as a command-line tool #8635

Open mjpieters opened 1 month ago

mjpieters commented 1 month ago

Given that the documentation suggests that you can use the docker container as a command-line tool I found it very surprising that you can't, in fact, use uv in this manner:

$ uv lock  # ensure there is an up-to-date lockfile
docker run --rm \
      --mount type=bind,source="$(pwd)",destination=/app --mount destination=/app/.venv \         
      ghcr.io/astral-sh/uv:latest \
           --directory /app -vv tree
    0.000473s DEBUG uv uv 0.4.27
    0.001380s DEBUG uv_workspace::workspace Found workspace root: `/app`
    0.001392s DEBUG uv_workspace::workspace Adding current workspace member: `/app`
    0.001800s DEBUG uv_python::discovery Searching for Python >=3.12 in managed installations or system path
    0.001841s DEBUG uv_python::discovery Searching for managed installations at `/.local/share/uv/python`
error: Could not read ELF interpreter from any of the following paths: /bin/sh, /usr/bin/env, /bin/dash, /bin/ls

The tree command should not require a Python interpreter (see #8634), but the ELF error here is especially confusing.

zanieb commented 1 month ago

We are attempting to sniff the platform to determine which managed installations are relevant. We might be able to fix that, I'm not quite sure how though.

You probably want one of the images that isn't distroless.

zanieb commented 1 month ago

cc @konstin should we set an environment variable in the distroless images for glibc? (or something else?)

konstin commented 1 month ago

We can't reliably sniff the glibc version from inside the container, at least if we want to also provision Python. What about something like -e UV_LIBC="$(/lib/ld-linux.so.2 --version)"/-e UV_LIBC="$(/lib/ld-musl-x86_64.so.1 --version)" (is there a platform independent one?) for docker where you pass in the context and we parse our the right libc kind and version?

mjpieters commented 1 month ago

Note that on MacOS, with Docker Desktop, docker itself runs inside a virtualised linux emulator, and so you can't trivially access /lib/ld-linux.so.2 or /lib/ld-musl-x86_64.so.1 from the host OS, at least not trivially.

konstin commented 1 month ago

Does that mean you want to use the docker uv with a host mac os python, not another linux Python?

zanieb commented 1 month ago

docker run --rm -it ghcr.io/astral-sh/uv:latest /bin/sh If this command fails, it means that the image itself may have problems.

That will always fail, and not because our image has problems — the image is distroless and only contains the uv binary.

samypr100 commented 1 month ago

You probably want one of the images that isn't distroless.

^this

mjpieters commented 3 weeks ago

Does that mean you want to use the docker uv with a host mac os python, not another linux Python?

Exactly. But, we'll use uv locally, instead.

(To be exact: uv is used to manage venvs inside docker containers, but for certain operations having uv run locally is just much much nicer, given how fast the tool is).