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

Add docs for Dockerfile ADD/COPY --chown flag #467

Merged
merged 1 commit into from
Nov 29, 2017

Conversation

estesp
Copy link
Contributor

@estesp estesp commented Aug 23, 2017

Document the new --chown flag added to the ADD and COPY commands in
the Dockerfile format.

Signed-off-by: Phil Estes estesp@linux.vnet.ibm.com

The actual implementation is ready to merge in moby/moby#34263

@codecov-io
Copy link

codecov-io commented Aug 23, 2017

Codecov Report

Merging #467 into master will decrease coverage by 2.67%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #467      +/-   ##
==========================================
- Coverage   49.41%   46.74%   -2.68%     
==========================================
  Files         208      199       -9     
  Lines       17186    16526     -660     
==========================================
- Hits         8493     7725     -768     
- Misses       8261     8400     +139     
+ Partials      432      401      -31

Copy link
Contributor

@mdlinville mdlinville left a comment

Choose a reason for hiding this comment

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

This review is for the docs only, not the merit of the feature. I found a couple places where there was room for improvement. My comments are about ADD but they also apply to COPY.

whitespace)

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>`.

Multiple `<src>` resource may be specified but if they are files or
Multiple `<src>` resources may be specified but if they are files or
directories then they must be relative to the source directory that is
Copy link
Contributor

Choose a reason for hiding this comment

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

directories, they must be

Also, "relative" I think means that they must be subdirectories of the build context? Maybe you can reword this to make it clearer.

All new files and directories are created with a UID and GID of 0.
All new files and directories are created with a UID and GID of 0, unless the
optional `--chown` flag is used to provide a user and group definition which
will be used to change the ownership of the created files and directories. The
Copy link
Contributor

Choose a reason for hiding this comment

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

How about "optional --chown flag specifies a given username, groupname, or UID/GID combination."

(if you only want to give a GID, how does Docker know it's not a UID? I think if you only provide a single integer it's always assumed to be a UID. Maybe best to state this too.)

@mdlinville
Copy link
Contributor

cc/ @gbarr01 for FYI

@@ -817,14 +817,14 @@ change them using `docker run --env <key>=<value>`.

ADD has two forms:

- `ADD <src>... <dest>`
- `ADD ["<src>",... "<dest>"]` (this form is required for paths containing
- `ADD [--chown <user>:<group>] <src>... <dest>`
Copy link
Contributor

Choose a reason for hiding this comment

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

Sure about that syntax? Not working for me & @presto9292 see moby/moby#34263 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @shouze ; you are correct that it requires an =; I will update this PR as it also has other edits required before being complete.

@estesp
Copy link
Contributor Author

estesp commented Sep 8, 2017

@mstanleyjones thanks for the review; I have updated per your comments; PTAL!

@shouze examples and flag documentation updated with the correct argument style--thanks for the catch!

@rcjsuen
Copy link
Contributor

rcjsuen commented Sep 9, 2017

What is the behaviour of using this flag on Windows as the /etc/passwd and /etc/group files do not exist there? Should this be included in the documentation?

@@ -848,7 +848,26 @@ named `arr[0].txt`, use the following;
ADD arr[[]0].txt /mydir/ # copy a file named "arr[0].txt" to /mydir/


All new files and directories are created with a UID and GID of 0.
All new files and directories are created with a UID and GID of 0, unless the
Copy link
Contributor

Choose a reason for hiding this comment

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

How do the concepts of UID and GID 0 map to Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They do not apply/map at all.. I assume we need a note about that :) A Dockerfile with the --chown flag on an ADD or COPY command will fail during docker build if it is built on a Windows Docker daemon.

This was discussed in the PR for the feature implementation itself--the other option was to "ignore" the flag on Windows but today this is not the way it is implemented.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we should add a header above this section; both for easier linking (anchor), and an introduction "This is a Linux-only feature". Also, the sections for COPY and ADD for this feature could then be combined if we think that's a good idea ("All new files and directories that are added through ADD or COPY ...."). (I'm sure @mstanleyjones has better suggestions 😄)

What is actually the owner of the files on Windows? (@johnstep?)

Copy link
Contributor

Choose a reason for hiding this comment

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

@estesp What I've seen is that passing --chown succeeds on Windows, if a number is supplied, but fails for a name since the code attempts to resolve the name by looking in \etc\passwd on Windows, which does not make sense.

Failing outright probably makes more sense, or at least warning, but I would prefer a more deliberate check and message. We have an issue on adding a warning, but it needs some more details: moby/moby#35026

@thaJeztah We'll look into how the owner is set on Windows. From a quick test, it seems to be set differently based on which directory a file is copied to, but we need to verify.

or direct integer UID and GID in any combination. Providing a username without
groupname or a UID without GID will use the name numeric UID as the GID. If a
username or groupname is provided, the container's root filesystem
`/etc/passwd` and `/etc/group` files will be used to perform the translation
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this map to Windows?

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

Left some thoughts 😄

combination to request specific ownership of the content added. The
format of the `--chown` flag allows for either username and groupname strings
or direct integer UID and GID in any combination. Providing a username without
groupname or a UID without GID will use the name numeric UID as the GID. If a
Copy link
Member

Choose a reason for hiding this comment

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

s/name/same/ (probably)

@@ -848,7 +848,26 @@ named `arr[0].txt`, use the following;
ADD arr[[]0].txt /mydir/ # copy a file named "arr[0].txt" to /mydir/


All new files and directories are created with a UID and GID of 0.
All new files and directories are created with a UID and GID of 0, unless the
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we should add a header above this section; both for easier linking (anchor), and an introduction "This is a Linux-only feature". Also, the sections for COPY and ADD for this feature could then be combined if we think that's a good idea ("All new files and directories that are added through ADD or COPY ...."). (I'm sure @mstanleyjones has better suggestions 😄)

What is actually the owner of the files on Windows? (@johnstep?)

combination to request specific ownership of the copied content. The
format of the `--chown` flag allows for either username and groupname strings
or direct integer UID and GID in any combination. Providing a username without
groupname or a UID without GID will use the name numeric UID as the GID. If a
Copy link
Member

Choose a reason for hiding this comment

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

s/name/same/

@mdlinville
Copy link
Contributor

I like the idea of a note like "The --chown and --chgrp features are only supported on Dockerfiles for Linux containers, and will not work on Windows containers." Maybe you can elaborate on what "will not work" looks like.

@thaJeztah
Copy link
Member

ping @estesp 😇

Document the new `--chown` flag added to the ADD and COPY commands in
the Dockerfile format.

Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
@estesp
Copy link
Contributor Author

estesp commented Oct 5, 2017

@mstanleyjones @thaJeztah updated; PTAL.

I did not combine the sections yet; I'm definitely willing to do so, but currently the anchor points are to each possible command in a Dockerfile; so I don't know what to name that anchor. Is it "ADD, COPY" or "ADD and COPY" or "ADD/COPY" ? :)

Given they are still distinct I added the same exact note about lack of capability on Windows to use the --chown feature.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

- `COPY <src>... <dest>`
- `COPY ["<src>",... "<dest>"]` (this form is required for paths containing
- `COPY [--chown=<user>:<group>] <src>... <dest>`
- `COPY [--chown=<user>:<group>] ["<src>",... "<dest>"]` (this form is required for paths containing
Copy link
Member

Choose a reason for hiding this comment

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

lol, this will be a bit confusing as the first square brackets are to indicate "it's optional" and the second are literal brackets for JSON.

Don't have a better suggestion at this point though (other than having an example perhaps) - I'm okay with adding that in a follow up

@estesp
Copy link
Contributor Author

estesp commented Oct 25, 2017

This feature went into the 17.09 release, so it currently undocumented as far as online docs. Is there anything else not addressed here? Just don't want it to get lost for too long!

@karser
Copy link

karser commented Oct 25, 2017

@estesp keep track changelog on docker-ce releases page to stay current

@mdlinville
Copy link
Contributor

@estesp well, this PR would have needed to be merged before docker/cli was merged into the appropriate docker/docker-ce branch. The docs currently pull the builder.md from https://github.com/docker/docker-ce/blob/17.09/components/cli/docs/reference/builder.md.

@rcjsuen
Copy link
Contributor

rcjsuen commented Oct 25, 2017

Unfortunately, this didn't make 17.10 either as far as I can tell. That's too bad but hey, it happens.

What outstanding issues are there left that are preventing it from being merged? I would like to add support for this flag in my project once the documentation has been finalized and is made available online.

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐸

@thaJeztah
Copy link
Member

I'll go ahead and merge 👍 thanks!

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.

10 participants