-
I am trying to enable a cache mount in my container build where the container user is non-root, and I was hoping that I could write the containerfile in such a way that it would work with both docker and podman. I have constructed the following minimal example to show the issue: ./ContainerfileFROM registry.access.redhat.com/ubi9/go-toolset:1.21.11-9 AS builder
WORKDIR /hello-world
COPY --chown=1001:0 ./ ./
ENV GOCACHE=/go-cache
RUN --mount=type=cache,target=${GOCACHE} go build main.go The file
Building with docker results in the following error:
Try the
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
A cache directory is reused based on its "id", or "target" if an "id" isn't set, and the ownership on a cache directory is set only when it's created the first time, so even after adding the "uid" option, you'd likely still have been using the same directory that was originally created for the default user "0:0". You should be able to clear it with It does appear that in |
Beta Was this translation helpful? Give feedback.
A cache directory is reused based on its "id", or "target" if an "id" isn't set, and the ownership on a cache directory is set only when it's created the first time, so even after adding the "uid" option, you'd likely still have been using the same directory that was originally created for the default user "0:0". You should be able to clear it with
podman system prune
while experimenting, or by using a unique "id" option to force a different cache to be created and used.It does appear that in
docker build
, cache directories are isolated by that owner UID as well, which would have prevented this conflict, so we need to fix that.