You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kaniko多阶段构建磁盘耗尽问题求助

Kaniko多阶段构建磁盘耗尽问题求助

使用Kaniko构建Docker镜像时,多阶段构建中第二阶段使用COPY --from=指令会耗尽/var/lib/docker的所有磁盘空间,报错信息如下:

error building image: could not save file: copying file: write /kaniko/0/dev/full: no space left on device

相同Dockerfile使用docker-ce直接构建无此问题,但该问题会导致同机器其他构建或容器失败,影响严重。

Kaniko构建失败控制台输出

$ docker run -v $(pwd):/workspace gcr.io/kaniko-project/executor:latest --dockerfile=./Dockerfile --context=/workspace --no-push
INFO[0000] Resolved base name registry.access.redhat.com/ubi8/ubi-minimal:8.6-902 to dependencies 
INFO[0000] Retrieving image manifest registry.access.redhat.com/ubi8/ubi-minimal:8.6-902 
INFO[0000] Retrieving image registry.access.redhat.com/ubi8/ubi-minimal:8.6-902 from registry registry.access.redhat.com 
INFO[0000] Retrieving image manifest registry.access.redhat.com/ubi8/ubi-minimal:8.6-902 
INFO[0000] Returning cached image manifest              
INFO[0000] Built cross stage deps: map[0:[.]]           
INFO[0000] Retrieving image manifest registry.access.redhat.com/ubi8/ubi-minimal:8.6-902 
INFO[0000] Returning cached image manifest              
INFO[0000] Executing 0 build triggers                   
INFO[0000] Building stage 'registry.access.redhat.com/ubi8/ubi-minimal:8.6-902' [idx: '0', base-idx: '-1'] 
INFO[0000] Unpacking rootfs as cmd RUN echo "Hello stage 1"   && touch A_FILE_PATH requires it. 
INFO[0003] ARG USER=nobody                              
INFO[0003] ARG A_FILE_PATH=/usr/bin/a_file              
INFO[0003] RUN echo "Hello stage 1"   && touch A_FILE_PATH 
INFO[0003] Initializing snapshotter ...                  
INFO[0003] Taking snapshot of full filesystem...        
INFO[0004] Cmd: /bin/sh                                 
INFO[0004] Args: [-c echo "Hello stage 1"   && touch A_FILE_PATH] 
INFO[0004] Running: [/bin/sh -c echo "Hello stage 1"   && touch A_FILE_PATH] 
Hello stage 1
INFO[0004] Taking snapshot of full filesystem...        
INFO[0004] Saving file . for later use                  
error building image: could not save file: copying file: write /kaniko/0/dev/full: no space left on device

Docker-ce成功构建日志

$ docker build - < Dockerfile
Sending build context to Docker daemon  2.048kB
Step 1/9 : FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6-902 AS dependencies
8.6-902: Pulling from ubi8/ubi-minimal
a96e4e55e78a: Pull complete 
67d8ef478732: Pull complete 
Digest: sha256:6e79406e33049907e875cb65a31ee2f0575f47afa0f06e3a2a9316b01ee379eb
Status: Downloaded newer image for registry.access.redhat.com/ubi8/ubi-minimal:8.6-902
 ---> c9882b8114e3
Step 2/9 : ARG USER=nobody
 ---> Running in 1aa898089bf3
Removing intermediate container 1aa898089bf3
 ---> da20079ed534
Step 3/9 : ARG A_FILE_PATH=/usr/bin/a_file
 ---> Running in fd2f43ef6a26
Removing intermediate container fd2f43ef6a26
 ---> b96ec1468dbd
Step 4/9 : RUN echo "Hello stage 1"   && touch A_FILE_PATH
 ---> Running in 0b98f322dda8
Hello stage 1
Removing intermediate container 0b98f322dda8
 ---> 2c74725b6be9
Step 5/9 : FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6-902
 ---> c9882b8114e3
Step 6/9 : ARG USER=nobody
 ---> Using cache
 ---> da20079ed534
Step 7/9 : COPY --from=dependencies ${A_FILE_PATH} ${A_FILE_PATH}
 ---> 2220a4d5ab88
Step 8/9 : RUN echo "Hello stage 2"
 ---> Running in 0efdca439c1e
Hello stage 2
Removing intermediate container 0efdca439c1e
 ---> aabbf5dabd6c
Step 9/9 : USER nobody
 ---> Running in 67b47ba45a95
Removing intermediate container 67b47ba45a95
 ---> b4ca6fa04f00
Successfully built b4ca6fa04f00

复现问题的Dockerfile

FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6-902 AS dependencies

ARG USER=nobody
ARG A_FILE_PATH=/usr/bin/a_file

RUN echo "Hello stage 1" \
  && touch A_FILE_PATH

FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6-902

ARG USER=nobody

COPY --from=dependencies ${A_FILE_PATH} ${A_FILE_PATH}
RUN echo "Hello stage 2"

USER nobody

内容的提问来源于stack exchange,提问作者Oscar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 17:20:55