Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divergent behavior when COPY tries to replace a symlink by a directory #2626

Open
dereckson opened this issue Feb 13, 2022 · 1 comment
Open

Comments

@dereckson
Copy link

dereckson commented Feb 13, 2022

There are several other issues with symbolic links, but I'm not sure this one has already been reported.

An image provides a directory structure including a files/etc/service folder.

The /etc/service path already exists on the image at that step, but as a symbolic link.

The legacy build mode is happy to supersede the symlink by a directory, without any warning.
BuildKit fails with a decent error message "cannot copy to non-directory" (decent enough it's easy to understand /etc/service existed, and not as a directory).

#11 [5/5] COPY files /
#11 sha256:335e11739def2fceb6f3b27b344e1634099fd311307c59064d902583cc5a15e1
#11 ERROR: cannot copy to non-directory: /var/lib/docker/overlay2/q4xakxgo6879bzw2t44ehm7j6/merged/etc/service
------
> [5/5] COPY files /:
------
error: failed to solve: rpc error: code = Unknown desc = cannot copy to non-directory: /var/lib/docker/overlay2/q4xakxgo6879bzw2t44ehm7j6/merged/etc/service
Build failed using Buildkit

On a legacy build, the image will be correctly built and the container has a folder:

$ file /etc/service
/etc/service: directory

A third scenario, not chosen by neither, could have been keep the symlink, follow it and populate target directory. That could lead to an image providing a full directory conf.d with the expectation it's only those files, to finally share them with previous existing files, because of the symlink.

Not sure the best approach on this one, could clearly be raise an error on legacy build mode instead of propagating a bug-as-a-feature into BuildKit.

@rittneje
Copy link
Contributor

I feel the situation here is ambiguous. There are two possible things the user could mean:

  1. the incoming directory replaces the symlink itself
  2. the incoming directory is merged into the target of the symlink

Without a flag to COPY or something, there's no way to know what the intent was. This is similar to the issue I described in #1260. Curiously, in that case symlinks to files got followed, but that logic evidently is not applied to symlinks to directories.

A separate yet related issue is the matter of COPYing a directory onto a file (or vice versa), which buildkit does not allow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants