@@ -1322,8 +1322,8 @@ The available `[OPTIONS]` are:
13221322| --------------------------------------- | -------------------------- |
13231323| [ ` --keep-git-dir ` ] ( #add---keep-git-dir ) | 1.1 |
13241324| [ ` --checksum ` ] ( #add---checksum ) | 1.6 |
1325- | [ ` --chown ` ] ( #add---chown--- chmod ) | |
1326- | [ ` --chmod ` ] ( #add---chown---chmod ) | 1.2 |
1325+ | [ ` --chmod ` ] ( #add---chmod ) | 1.2 |
1326+ | [ ` --chown ` ] ( #add---chown ) | |
13271327| [ ` --link ` ] ( #add---link ) | 1.4 |
13281328| [ ` --unpack ` ] ( #add---unpack ) | 1.17 |
13291329| [ ` --exclude ` ] ( #add---exclude ) | 1.19 |
@@ -1586,9 +1586,13 @@ ADD --checksum=be1f38e https://github.com/moby/buildkit.git#v0.26.2 /
15861586ADD --checksum=sha256:24454f830cdb571e2c4ad15481119c43b3cafd48dd869a9b2945d1036d1dc68d https://mirrors.edge.kernel.org/pub/linux/kernel/Historic/linux-0.01.tar.gz /
15871587```
15881588
1589- ### ADD --chown -- chmod
1589+ ### ADD --chmod
15901590
1591- See [ ` COPY --chown --chmod ` ] ( #copy---chown---chmod ) .
1591+ See [ ` COPY --chmod ` ] ( #copy---chmod ) .
1592+
1593+ ### ADD --chown
1594+
1595+ See [ ` COPY --chown ` ] ( #copy---chown ) .
15921596
15931597### ADD --link
15941598
@@ -1633,8 +1637,8 @@ The available `[OPTIONS]` are:
16331637| Option | Minimum Dockerfile version |
16341638| ---------------------------------- | -------------------------- |
16351639| [ ` --from ` ] ( #copy---from ) | |
1636- | [ ` --chown ` ] ( #copy---chown--- chmod ) | |
1637- | [ ` --chmod ` ] ( #copy---chown---chmod ) | 1.2 |
1640+ | [ ` --chmod ` ] ( #copy---chmod ) | 1.2 |
1641+ | [ ` --chown ` ] ( #copy---chown ) | |
16381642| [ ` --link ` ] ( #copy---link ) | 1.4 |
16391643| [ ` --parents ` ] ( #copy---parents ) | 1.20 |
16401644| [ ` --exclude ` ] ( #copy---exclude ) | 1.19 |
@@ -1804,32 +1808,50 @@ COPY --from=nginx:latest /etc/nginx/nginx.conf /nginx.conf
18041808The source path of ` COPY --from ` is always resolved from filesystem root of the
18051809image or stage that you specify.
18061810
1807- ### COPY --chown -- chmod
1811+ ### COPY --chmod
18081812
1809- > [ !NOTE]
1810- > Only octal notation is currently supported. Non-octal support is tracked in
1811- > [ moby/buildkit #1951 ] ( https://github.com/moby/buildkit/issues/1951 ) .
1813+ ``` dockerfile
1814+ COPY [--chmod=<perms>] <src> ... <dest>
1815+ ```
1816+
1817+ The ` --chmod ` flag supports octal notation (e.g., ` 755 ` , ` 644 ` ).
1818+ Symbolic notation (e.g., ` +x ` , ` g=u ` ) requires the ` docker/dockerfile:1-labs `
1819+ syntax directive. This is useful when octal isn't flexible enough. For example,
1820+ ` u=rwX,go=rX ` sets directories to 755 and files to 644, while preserving the
1821+ executable bit on files that already have it. (Capital ` X ` means "executable
1822+ only if it's a directory or already executable.")
1823+
1824+ Examples using octal notation:
1825+
1826+ ``` dockerfile
1827+ COPY --chmod=755 app.sh /app/
1828+ COPY --chmod=644 file.txt /data/
1829+ ARG MODE=440
1830+ COPY --chmod=$MODE . .
1831+ ```
1832+
1833+ Examples using symbolic notation (labs only):
18121834
18131835``` dockerfile
1814- COPY [--chown=<user>:<group>] [--chmod=<perms> ...] <src> ... <dest>
1836+ # syntax=docker/dockerfile:1-labs
1837+ COPY --chmod=+x script.sh /app/
1838+ COPY --chmod=u=rwX,go=rX . /app/
1839+ COPY --chmod=g=u config/ /config/
18151840```
18161841
1817- The ` --chown ` and ` --chmod ` features are only supported on Dockerfiles used to build Linux containers,
1818- and doesn't work on Windows containers. Since user and group ownership concepts do
1819- not translate between Linux and Windows, the use of ` /etc/passwd ` and ` /etc/group ` for
1820- translating user and group names to IDs restricts this feature to only be viable for
1821- Linux OS-based containers.
1842+ The ` --chmod ` flag is not supported when building Windows containers.
18221843
1823- All files and directories copied from the build context are created with a UID and GID of ` 0 ` unless the
1824- optional ` --chown ` flag specifies a given username, groupname, or UID/GID
1825- combination to request specific ownership of the copied content. The
1826- format of the ` --chown ` flag allows for either username and groupname strings
1827- or direct integer UID and GID in any combination. Providing a username without
1828- groupname or a UID without GID will use the same numeric UID as the GID. If a
1829- username or groupname is provided, the container's root filesystem
1830- ` /etc/passwd ` and ` /etc/group ` files will be used to perform the translation
1831- from name to integer UID or GID respectively. The following examples show
1832- valid definitions for the ` --chown ` flag:
1844+ ### COPY --chown
1845+
1846+ ``` dockerfile
1847+ COPY [--chown=<user>:<group>] <src> ... <dest>
1848+ ```
1849+
1850+ Sets ownership of copied files. Without this flag, files are created with UID
1851+ and GID of 0.
1852+
1853+ The flag accepts usernames, group names, UIDs, or GIDs in any combination.
1854+ If you specify only a user, the GID is set to the same numeric value as the UID.
18331855
18341856``` dockerfile
18351857COPY --chown=55:mygroup files* /somedir/
@@ -1839,22 +1861,12 @@ COPY --chown=10:11 files* /somedir/
18391861COPY --chown=myuser:mygroup --chmod=644 files* /somedir/
18401862```
18411863
1842- If the container root filesystem doesn't contain either ` /etc/passwd ` or
1843- ` /etc/group ` files and either user or group names are used in the ` --chown `
1844- flag, the build will fail on the ` COPY ` operation. Using numeric IDs requires
1845- no lookup and does not depend on container root filesystem content.
1846-
1847- With the Dockerfile syntax version 1.10.0 and later,
1848- the ` --chmod ` flag supports variable interpolation,
1849- which lets you define the permission bits using build arguments:
1864+ When using names instead of numeric IDs, BuildKit resolves them using
1865+ ` /etc/passwd ` and ` /etc/group ` in the container's root filesystem. If these
1866+ files are missing or don't contain the specified names, the build fails.
1867+ Numeric IDs don't require this lookup.
18501868
1851- ``` dockerfile
1852- # syntax=docker/dockerfile:1.10
1853- FROM alpine
1854- WORKDIR /src
1855- ARG MODE=440
1856- COPY --chmod=$MODE . .
1857- ```
1869+ The ` --chown ` flag is not supported when building Windows containers.
18581870
18591871### COPY --link
18601872
0 commit comments