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

COPY --link incompatibility with COPY --chown + Both flags undocumented effect on existing destination path parents #20660

Open
1 task done
polarathene opened this issue Aug 20, 2024 · 0 comments
Labels
area/build Relates to Dockerfiles or docker build command status/triage Needs triage

Comments

@polarathene
Copy link
Contributor

polarathene commented Aug 20, 2024

Is this a docs issue?

  • My issue is about the documentation content or website

Type of issue

I can't find what I'm looking for

Description

Actionables:

  • COPY --chown + COPY --link should document their effect on modifying the permissions of any existing directories of the destination path provided. --chmod does not behave in this manner which only adds to confusion.
    • While the COPY --chown docs mention default ownership of the copied source content is 0:0 (regardless of --link):
      • This actually differs when using the --from flag (without a --chown override) to specify a different stage or image where the COPY source content ownership is preserved. This is demonstrated here with a visual + reproduction. As opposed to COPY with git and local contexts (instead of via --from), where the original ownership is not preserved (becomes 0:0 in container).
      • It is only the parent dirs (if any) of the COPY target path that will use the fallback 0:0 755. However... if those parent dirs did already exist and --link is used, their ownership and permission will also be replaced by 0:0 755 (the implicit FROM scratch that --link introduces for it's rebase layer causes that).
    • The COPY source content permissions are preserved (regardless of --link), unless intentionally overriding with --chmod.
    • NOTE: BuildKit 0.13.2 introduced 777 (dir) + 666 (file) permissions for checkout via git context when no umask was applied?, fixed in BuildKit 0.15.2 (PR). Not applicable to the local build context.
  • The COPY --chown with non-numeric values section should highlight awareness of COPY --link being a common case for the vague build error it outputs:
    Error: buildx failed with: ERROR: failed to solve: invalid user index: -1
    
  • Related, mode= (the --chmod equivalent) for RUN --mount=type=cache ... has two known quirks to consider documenting:
    • The mode= option will persist a cache mount across builds with --no-cache (which would normally discard the cache).
    • docker buildx build --builder docker ... (default for docker build ...) prior to BuildKit 0.15.2 will apply 022 umask to a configured mode= value of the cache target= (mode=773 sets 751 on the target dir). Yet does not apply to docker-container driver running BuildKit prior to 0.15.2.

Full report details

COPY --link does not describe it's affect on parent directories where the permissions and ownership are modified to 755 0:0.

Perhaps because this seems to be specific to the docker buildx build --builder ... driver used, at least with docker-container it occurs while it does not with the docker driver. The behaviour also differs in the context of --chmod and --chown usage with --link.

More information about this inconsistency here:

The docs do not indicate how to verify --link is being used.

It would be good for the docs to at least clarify the --link scenario that may result in unexpected permissions/ownership changes to parent dirs of the target path. And if the --chmod=null workaround has any relevant concerns before that potentially spreads in adoption.


In the context of --link --chown=invalid, this is hinted at in the docs:

https://docs.docker.com/reference/dockerfile/#copy---chown---chmod

If the container root filesystem doesn't contain either /etc/passwd or /etc/group files and either user or group names are used in the --chown flag, the build will fail on the COPY operation. Using numeric IDs requires no lookup and does not depend on container root filesystem content.

However, as has been seen in various reports regarding these two features.. it's often not understood that --link is the cause when a build outputs this unhelpful error message. Some projects respond to this by removing --link, or finding a way to ensure the UID/GID values are deterministic.

That section should be amended to cite the common case with --link?


Potentially relevant context:


Location

https://docs.docker.com/reference/dockerfile/#copy

Suggestion

Suggestions above under Actionables.

  • Needs to be worded into proper documentation, plenty of reference context linked and insights provided to assist with that.
  • EDIT: I've sense appended to this list additional caveats from other COPY flags that should be accounted for. Along with semi-related concerns with RUN.

Usually the doc issues I engage with here become stale and locked by the docker bot, never to be addressed. Thus the above is serves as an informal documentation reference if that occurs.

Some of the observed behaviour may be bugs that will get addressed. Docs could be delayed, but note that some of these concerns have been known for well over a year, if that continues it may be better to document the caveat for the benefit of users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build Relates to Dockerfiles or docker build command status/triage Needs triage
Projects
None yet
Development

No branches or pull requests

2 participants