FROM ubuntu
RUN groupadd -g 9999 app && useradd -m -g 9999 -u 9999 app
USER app
WORKDIR /home/app
COPY . /home/app
RUN --mount=type=cache,uid=9999,gid=9999,target="/home/app/tmp_data" \
echo "Listing BEFORE writing." &&\
(ls -l /home/app/tmp_data/test.txt || echo "File not yet created") &&\
echo "THIS IS A TEST" > /home/app/tmp_data/test.txt &&\
echo "Listing file AFTER writing." &&\
ls -l /home/app/tmp_data/test.txt
Run docker buildx build --progress plain -t test-ownership ..
(you have to be root user to preserve ownership when extracting) Extract cache by running node ./buildkit-cache-dance/dist/index.js --extract --cache-map '{"<path-to-cache-directory>/cache_dir": {"target": "/home/app/tmp_data", "uid": "9999", "gid": "9999"}}'.
Invalidate build cache by adding a file. e.g. touch invalidate_cache.
How to reproduce:
test_ownership
docker buildx build --progress plain -t test-ownership .
.root
user to preserve ownership when extracting) Extract cache by runningnode ./buildkit-cache-dance/dist/index.js --extract --cache-map '{"<path-to-cache-directory>/cache_dir": {"target": "/home/app/tmp_data", "uid": "9999", "gid": "9999"}}'
.touch invalidate_cache
.docker buildx prune
.node ./buildkit-cache-dance/dist/index.js --cache-map '{"<path-to-cache-directory>/cache_dir": {"target": "/home/app/tmp_data", "uid": "9999", "gid": "9999"}}'
docker buildx build --progress plain -t test-ownership .
.You should see error like this:
Also, the output of
ls
command shows that the owner isroot
.