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

docs: clarify leading and trailing slashes in add/copy source path #5664

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

dvdksn
Copy link
Collaborator

@dvdksn dvdksn commented Jan 15, 2025

Leading and trailing slashes in the source path for ADD and COPY, when
adding/copying files from the build context, have no effect.

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
@crazy-max crazy-max merged commit 78bcf8d into moby:master Jan 15, 2025
31 checks passed
@dvdksn dvdksn deleted the tidy-dockerfile-add-copy-localsrc branch January 15, 2025 15:15
relative to the root of the context.

Specifying a source path with a leading slash or one that navigates outside the
build context, such as `COPY ../something /something`, automatically removes
Copy link
Member

Choose a reason for hiding this comment

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

Do we document somewhere that for the destination the path may be resolved relative to the WORKDIR that's set, so if it's a relative path (I think) we resolve it relative to the active WORKDIR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doesn't look like we describe that too well... only indirectly. I guess we could do with a bit more clarity there too. I can do a followup.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, never mind me. We do describe it. I'm just bad at reading documentation.


Specifying a source path with a leading slash or one that navigates outside the
build context, such as `COPY ../something /something`, automatically removes
any parent directory navigation (`../`). Trailing slashes in the source path
Copy link

Choose a reason for hiding this comment

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

In the example you gave, does COPY ../something /something get treated as COPY something /something? It's not immediately clear that this is the case...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, COPY ../something /something and COPY something /something are equivalent

Copy link

Choose a reason for hiding this comment

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

@dvdksn Any chance you could add this clarification to the updated document? Here is what the updated version would look like:

Specifying a source path with a leading slash or one that navigates outside the
build context, such as COPY ../something /something, automatically removes
any parent directory navigation (../), making COPY ../something/ /something equivalent to COPY something /something.

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.

5 participants