kaniko: COPY resolves symlinks it shouldn't try to resolve
Actual behavior
Since v0.18.0, COPY tries to resolve some symlinks it shouldn’t try to resolve, which is a regression.
Expected behavior
I would expect kaniko to let those symlinks remain symlinks when copied in the image.
To Reproduce
For instance, we can create a symlink that points to nothing to make kaniko crash:
mkdir example
cd example/
echo "FROM alpine\nCOPY . /example" > Dockerfile
ln -s ./missing symlink
docker run --rm -it -v $(pwd):/workspace:ro gcr.io/kaniko-project/executor:debug --no-push
👇 👇 👇
[…]
error building image: error building stage: failed to execute command: lstat /workspace/missing: no such file or directory
If we create the symlink target, it builds successfully but the symlink is replaced with a plain file within the image:
touch missing
docker run --rm -it -v $(pwd):/workspace:ro --entrypoint='' gcr.io/kaniko-project/executor:debug /busybox/sh -c '/kaniko/executor --no-push && ls -l /example/'
👇 👇 👇
[…]
total 4
-rw-r--r-- 1 1000 1000 29 Mar 6 14:28 Dockerfile
-rw-r--r-- 1 1000 1000 0 Mar 6 14:28 missing
-rw-r--r-- 1 1000 1000 0 Mar 6 14:28 symlink
Whereas in v0.17.1 (or using docker build) the symlink is not resolved:
$ docker run --rm -it -v $(pwd):/workspace:ro --entrypoint='' gcr.io/kaniko-project/executor:debug-v0.17.1 /busybox/sh -c '/kaniko/executor --no-push && ls -l /example/'
[…]
total 8
-rw-r--r-- 1 1000 1000 29 Mar 6 14:29 Dockerfile
-rw-r--r-- 1 1000 1000 0 Mar 6 14:29 missing
lrwxrwxrwx 1 root root 9 Mar 6 14:29 symlink -> ./missing
Additional Information
This is a regression from v0.18.0. It worked properly in v0.17.1.
Note that Kaniko v0.18.0 changed the way symlinks work to better match actual Docker’s behavior. That probably introduced this bug as a side-effect.
Triage Notes for the Maintainers
| 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 |
|
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 10
- Comments: 19 (14 by maintainers)
I got this minimal Dockerfile to fail on v0.18.0 and v0.19.0 when building with target
twousing--target two(building targetoneworks fine though, so it seems the other target is somehow interfering). v0.17.1 is working fine so I suspect it must be related to this issue. Hope it is of any help for testing. The Dockerfile:Resulting log from
basestage:@bramus Tried your issue on latest v0.19.0 build and it does not work. i will add a fix in next release.
Also having symlink issues with an image containing a PHP app, where its dependency manager (Composer) will create symlinks to provided binaries.
When building using Docker itself, the files are – as expected – symlinked into
vendor/bin/:When building using kaniko, the files in the
vendor/bin/are no symlinks but actual copies:For reference, the Composer dependencies were built in a separate image, and then
COPY’d into the main image (e.g. multi-stage build):EDIT: Is this this issue, or is it #437 ?
Thanks @WestonThayer The error you are seeing is due to #1112 and not due to symlinks.
Thank you. I can confirm this issue is fixed on
debug-edge.yes i am. The reason why we made that change was to mimic what docker does and picked up the regression. I will work on fixing it and fixing the tests.