Summary
The current guidance for caching in docker images is:
ENV UV_LINK_MODE=copy
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync
The UV_LINK_MODE=COPY is crucial, as the cache is not mounted during container runtime.
However, this only works for package cache, and not for managed python installations. So if my image doesn't have python already installed, uv downloads it and puts it in a non-cached filesystem (/root/.local/share/uv by default). It would be nice if there was some way to have a UV_LINK_MODE analog, but for managed python so that if one mounts a python cache, uv sync will copy python to the image filesystem.
Summary
The current guidance for caching in docker images is:
The
UV_LINK_MODE=COPYis crucial, as the cache is not mounted during container runtime.However, this only works for package cache, and not for managed python installations. So if my image doesn't have python already installed, uv downloads it and puts it in a non-cached filesystem (
/root/.local/share/uvby default). It would be nice if there was some way to have aUV_LINK_MODEanalog, but for managed python so that if one mounts a python cache,uv syncwill copy python to the image filesystem.