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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions frontend/dockerfile/docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1280,11 +1280,11 @@ relative to the build context. For example, if the build context is the current
directory, `ADD file.txt /` adds the file at `./file.txt` to the root of the
filesystem in the build container.

When adding source files from the build context, their paths are interpreted as
relative to the root of the context. If you specify a relative path leading
outside of the build context, such as `ADD ../something /something`, parent
directory paths are stripped out automatically. The effective source path in
this example becomes `ADD something /something`.
Specifying a source path with a leading slash or one that navigates outside the
build context, such as `ADD ../something /something`, automatically removes any
parent directory navigation (`../`). Trailing slashes in the source path are
also disregarded, making `ADD something/ /something` equivalent to `ADD
something /something`.

If the source is a directory, the contents of the directory are copied,
including filesystem metadata. The directory itself isn't copied, only its
Expand Down Expand Up @@ -1556,11 +1556,14 @@ For more information about copying from named sources, see the

#### Copying from the build context

When copying source files from the build context, their paths are interpreted as
relative to the root of the context. If you specify a relative path leading
outside of the build context, such as `COPY ../something /something`, parent
directory paths are stripped out automatically. The effective source path in
this example becomes `COPY something /something`.
When copying source files from the build context, paths are interpreted as
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.

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.

are also disregarded, making `COPY something/ /something` equivalent to `COPY
something /something`.

If the source is a directory, the contents of the directory are copied,
including filesystem metadata. The directory itself isn't copied, only its
Expand Down
Loading