Kaniko deletes all content inside `$HOME` directory when using multiple `FROM` elements inside `Dockerfile`.
Author: GamePlayer-8Created Sep 28, 2023Updated Jun 2, 2025
Labelskind/bugarea/multi-stage buildspriority/p0area/filesystemsneeds-discussionworks-with-dockerdiffers-from-dockerissue/missing-files
Actual behavior
When I'm using multiple FROM <image name> inside Dockerfile kaniko somehow deletes everything inside $HOME directory (at least when running on root). Causing the push option of the image to error since the credentials are stored in $HOME/.docker.
Expected behavior
Kaniko should build an image with multiple FROM <image name> elements just fine, without deleting content inside $HOME and pushing the image without any problem.
To Reproduce Steps to reproduce the behavior:
- Install
kanikoinside i.e.alpinecontainer. - Install
docker - Create credentials file with
docker login - Create an example
Dockerfileoutside of$HOMEdirectory:
FROM alpine AS builder
RUN echo "First image."
FROM alpine
COPY --from=builder /bin/sh .
RUN echo "Second image."
CMD ["/bin/sh"]- Build a Docker image and try to push it onto the specified docker registry (from
docker login). Use commandkaniko --context . --dockerfile ./Dockerfile --destination your.registry/username/package - kaniko should crash and after doing
ls -a $HOMEthe directory should be shown as empty.
| Description | Yes/No |
|---|---|
| Please check if this a new feature you are proposing |
|
| Please check if the build works in docker but not in kaniko |
|
Please check if this error is seen when you use --cache flag |
|
| Please check if your dockerfile is a multistage dockerfile |
|
Source: GoogleContainerTools/kaniko