Open sbeaulie opened 3 years ago
kaniko does not use this directory in the setup you provided so it would be safe to use directly. It would "use" it if you specified "--context=/workspace" but that isn't the case here so it is fine. kaniko does use essentially 2 root directories for its operation: /kaniko /<the provided --context= value>
This directory exists as a side effect of setting the WORKDIR
as /workspace
in the kaniko executor image directly when we create the kaniko executor image we release - gcr.io/kaniko-project/executor:latest
https://github.com/GoogleContainerTools/kaniko/blob/main/deploy/Dockerfile#L86
WORKDIR /workspace
I believe it is actually docker that is creating this /workspace
directory as it is specified as the WORKDIR for the gcr.io/kaniko-project/executor:latest image:
aprindle@aprindle-ssd ~/kaniko [main]docker image inspect -f '{{.Config.WorkingDir}}' gcr.io/kaniko-project/executor:latest
/workspace
A potential fix for this issue would be to change the kaniko image to not have a WORKDIR specified (or make it /kaniko or something like that), currently I am trying to decide between the relative priority of fixing this issue vs possibly breaking WORKDIR relative paths for that who might rely on that in the image.
This is also related to a problem with GitLab CI/CD, which recommends using Kaniko for Kubernetes builds.
In a multi-stage Dockerfile, Kaniko will, between stages, delete the entire filesystem except ignored paths; see https://github.com/GoogleContainerTools/kaniko/blob/8d7d925a735a1bf0d30de64036d6ee61a0cbf9ab/pkg/executor/build.go#L745
In GitLab CI/CD, many actions (such as an after_script
or saving artifacts) will try to run new commands, and try to start those commands in the WORKDIR
. Since /workspace
was deleted, then this fails.
This is documented with workarounds at https://docs.gitlab.com/runner/executors/kubernetes.html#use-kaniko-to-build-docker-images and in https://gitlab.com/gitlab-org/gitlab-runner/-/issues/30769#note_1452088669 , but obviously it would be better if the Kaniko image wasnโt built in a way that hits this issue.
While I was researching this, I got the impression (I may be mistaken) that /workspace
was previously used for a similar purpose to how /kaniko
is used today, and the WORKDIR
is probably an remnant of that.
I see that youโve already written a fix, although it looks like the merge is blocked at the moment. I thought Iโd just make a note of this here, to help users find it.
Any update on this? Just hit the same issue.
Actual behavior If a dockerfile has a step to create a directory /workspace, kaniko fails.
Expected behavior Parity with the docker behavior, I expected it to pass like docker build
To Reproduce Simple Dockerfile
running with docker passes
running with kaniko fails with mkdir: can't create directory '/workspace': File exists
Additional Information
I stumbled on this issue and couldn't find any documentation or report in kaniko for this. It is easy to workaround the issue by putting
mkdir -p /workspace
but I'm worried that kaniko uses that directory internally and it could conflict with what docker is trying to do. Can one of the maintainers confirm? I can imagine more complex examples where permissions and user chown to that directory could potentially be needed for the docker container and mess things up? Is it bad practice to have a dockerfile use /workspace? If the answer is yes, in that case this should be documented, or I would prefer the kaniko code be changed so that users do not inavertently use internal directory structures needed by kaniko.Triage Notes for the Maintainers
--cache
flag