Skip to content

docs: clarify a caveat with COPY --link and overwriting directory permissions - #6778

Merged
tonistiigi merged 1 commit into
moby:masterfrom
jsternberg:copy-link-clarify-permission-overwriting
May 29, 2026
Merged

docs: clarify a caveat with COPY --link and overwriting directory permissions#6778
tonistiigi merged 1 commit into
moby:masterfrom
jsternberg:copy-link-clarify-permission-overwriting

Conversation

@jsternberg

Copy link
Copy Markdown
Collaborator

Closes #3602.

Comment thread frontend/dockerfile/docs/reference.md Outdated
conditions for cache reuse.

When copying a path into a subdirectory, `--link` will always create the
parent directories with the default directory creation settings and will always

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always create the
parent directories with the default directory creation settings

I think it creates the parent directories in whatever settings that were set by the copy command.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My observed behavior was that parent directories were created with 0755. I'm not sure if that's what's intended but it was the behavior I saw.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be the same as COPY without --link on top of scratch stage.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be related to umask. I tested this on a Mac with Docker Desktop and the VM seems to have a umask of 0022 which may have influenced the results. The code to create these directories seems to be intended to use the --chmod setting but umask may have interfered here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a note about umask in the COPY --chmod section and how it can affect creating parent directories.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umask of the system should never affect the output of buildkit. We are clearing umask in https://github.com/moby/buildkit/blob/master/cmd/buildkitd/main_unix.go#L19

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just spoke with @tonistiigi about this and there may be some kind of bug. The current behavior definitely seems to apply umask to the created directories but it does appear that it shouldn't be doing that. I'll have to investigate further.

@jsternberg
jsternberg force-pushed the copy-link-clarify-permission-overwriting branch from 9b10935 to d87c25f Compare May 15, 2026 15:45
Comment thread frontend/dockerfile/docs/reference.md Outdated

Parent directories will be created with the same mode that is specified by this
flag. This can be affected by the process umask. This is most common when
attempting to copy with mode `777` since the common umask of `022` can change

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true. As I wrote in the previous comment, BuildKit behavior is unaffected by system umask.

@jsternberg
jsternberg force-pushed the copy-link-clarify-permission-overwriting branch from d87c25f to ae129ab Compare May 27, 2026 15:36
…ermissions

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
@jsternberg
jsternberg force-pushed the copy-link-clarify-permission-overwriting branch from ae129ab to 448f9d3 Compare May 28, 2026 20:25
@tonistiigi
tonistiigi merged commit 678d51f into moby:master May 29, 2026
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COPY command changes the directory permissions to change.

2 participants