Docker构建导出本地时.tmp文件元数据设置权限错误求助
问题:Docker build导出本地时.tmp文件权限设置失败
我在Ubuntu 23.10上使用Docker 24.0.5(build ced0996)执行docker build时,过程中生成了一个0字节的.tmp.xxxxxx随机命名文件,复制到本地时抛出权限错误:
ERROR: failed to solve: error from receiver: error setting metadata for build/.tmp.680872741: lchown build/.tmp.680872741: operation not permitted
我的artifacts.Dockerfile内容如下:
# use the build image as a transient container for the build FROM release-build AS build # build in the home folder WORKDIR /home/project # copy the assets and dependencies into the build images source directory COPY build/ . # build the component #RUN make project 1>>build.txt 2>>build.txt # copy the object, dependencies, and entire build to the local file system FROM scratch COPY --from=build /home/project /
已注释掉make命令,确认该tmp文件由Docker创建。构建命令:
sudo cat artifacts.Dockerfile | docker build --no-cache --file - --output type=local,dest=build .
完整构建输出:
=> [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 723B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/release-build:latest 0.0s => [build 1/3] FROM docker.io/library/release-build 0.0s => [internal] load build context 0.0s => => transferring context: 26.09kB 0.0s => CACHED [build 2/3] WORKDIR /home/project 0.0s => [build 3/3] COPY build/ . 0.0s => [stage-1 1/1] COPY --from=build /home/project / 0.0s => ERROR exporting to client directory 0.0s => => copying files 1.89kB 0.0s ------ > exporting to client directory: ------ ERROR: failed to solve: error from receiver: error setting metadata for build/.tmp.680872741: lchown build/.tmp.680872741: operation not permitted
该tmp文件构建前不存在,失败后出现在本地,说明已复制但属性设置失败。我已尝试以下方法均无效:
- 带sudo/不带sudo执行构建命令
- 在最终COPY步骤添加
--chown 1000:1000(匹配本地用户ID) - 不使用
cat直接指定Dockerfile路径绕过缓存
观察到:注释COPY build/ .命令则不会生成该tmp文件;改为复制单个文件时仍会生成。目前不知道如何避免该tmp文件的创建/复制,或解决权限错误,恳请提供思路。
内容的提问来源于stack exchange,提问作者mark
相关产品推荐
相关产品推荐

