I am using kaniko to build my docker images and stumbled upon a strange issue when doing multistage builds.
When using COPY --from= in the second stage, kaniko seems to eat up all diskspace in /var/lib/docker (using docker-ce):
$ df -h
...
/disks/docker 2T 2T 53M 100% /var/lib/docker
...
The console output when doing a kaniko build looks like:
$ 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
This does not happen when I build the image with 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
The Dockerfile to reproduce this looks like:
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
The fact that kaniko makes docker to eat up all disk-space is causing other builds or containers to fail on the same machine. This is a pretty severe side effect.
I also posted my finding in https://github.com/GoogleContainerTools/kaniko/issues/2203 but there seems to be no activity in the project to analyze this.
1条答案
按热度按时间7dl7o3gd1#
我在gitlab-ci管道中使用
gcr.io/kaniko-project/executor:v1.9.0-debug
时也遇到了同样的问题(使用多级Dockerfile)。