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: rewrite copy/add instruction reference #5128

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

dvdksn
Copy link
Collaborator

@dvdksn dvdksn commented Jul 5, 2024

Updates the sections for COPY and ADD in the Dockerfile reference to make it
easier to understand the behaviors of these instructions in different
circumstances.

Also adds some information about permissions for COPY with Git contexts.

Preview:

Relates to:

@dvdksn dvdksn marked this pull request as ready for review July 5, 2024 12:44
@dvdksn dvdksn force-pushed the dockerfile-reference-copy-add branch from 2540e8e to 56d154b Compare July 8, 2024 08:50
> **Note**
>
> The first encountered `ADD` instruction will invalidate the cache for all
> following instructions from the Dockerfile if the source has changed. This
Copy link
Member

Choose a reason for hiding this comment

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

Invalidate cache for the following commands in the same stage is what you probably mean. But even that is not true for all cases, eg. COPY --link

Also, this behavior isn't really specific to ADD or COPY command.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can remove this, we cover cache invalidation elsewhere.

@@ -1160,41 +1160,96 @@ The available `[OPTIONS]` are:
- [`--link`](#add---link)
- [`--exclude`](#add---exclude)

The `ADD` instruction copies new files, directories or remote file URLs from `<src>`
and adds them to the filesystem of the image at the path `<dest>`.
The `ADD` instruction copies new files or directories from `<src>` and adds
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to have some comparison of ADD/COPY or guidance on when to use which one. I've seen plenty of recommendations that "you should use COPY and not ADD," and while that might be a good idea for consistency, they sometimes imply that COPY is faster or smth. what is not true.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We do have a section on this in the best practices document. https://docs.docker.com/build/building/best-practices/#add-or-copy

I can add a reference to that doc from these sections.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can of course expand on that section too - let me know if you have some suggestions

If the source is a directory, the contents of the directory are copied,
including filesystem metadata. The directory itself isn't copied, only its
contents. If it contains subdirectories, these are also copied, and merged with
any existing directories at the destination. Any conflicts are resolved in
Copy link
Member

Choose a reason for hiding this comment

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

Any conflicts are resolved in

Not worth complicating probably, but this is true if files are of the same type. If you have a directory and replace it with a regular file, you get an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can add this, just to avoid any confusion.

#### Adding local tar archives

When using a local tar archive as the source for `ADD`, and the archive is in a
recognized compression format (`identity`, `gzip`, `bzip2` or `xz`), the
Copy link
Member

Choose a reason for hiding this comment

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

identity ?

Do you mean gzip, bzip2, xz or uncompressed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably! I didn't touch this sentence but sounds better to me, I'll update

@dvdksn dvdksn force-pushed the dockerfile-reference-copy-add branch from 56d154b to 60c86c4 Compare July 9, 2024 10:47
@dvdksn dvdksn requested a review from tonistiigi July 9, 2024 10:47
@thompson-shaun thompson-shaun added this to the v0.15.0 milestone Jul 9, 2024
@tonistiigi tonistiigi merged commit 5b5afdb into moby:master Jul 10, 2024
18 checks passed
@dvdksn dvdksn deleted the dockerfile-reference-copy-add branch July 10, 2024 04:36
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