COPY --chown --chmod
The--chownand--chmodfeatures are only supported on Dockerfiles used to build Linux containers,
and doesn't work on Windows containers. Since user and group ownership concepts do
not translate between Linux and Windows, the use of/etc/passwdand/etc/groupfor
translating user and group names to IDs restricts this feature to only be viable for
Linux OS-based containers.
All files and directories copied from the build context are created with a UID and GID of0unless the
optional--chownflag specifies a given username, groupname, or UID/GID
combination to request specific ownership of the copied content. The
format of the--chownflag 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 same numeric UID as the GID. If a
username or groupname is provided, the container's root filesystem/etc/passwdand/etc/groupfiles will be used to perform the translation
from name to integer UID or GID respectively. The following examples show
valid definitions for the--chownflag:
If the container root filesystem doesn't contain either/etc/passwdor/etc/groupfiles and either user or group names are used in the--chownflag, the build will fail on theCOPYoperation. Using numeric IDs requires
no lookup and does not depend on container root filesystem content.
With the Dockerfile syntax version 1.10.0 and later,
the--chmodflag supports variable interpolation,
which lets you define the permission bits using build arguments: