Dockerfile instructions
COPY --chown
Linux image copy ownership option. Numeric IDs avoid name resolution in the target filesystem. Check permissions and intended runtime user; ownership is not itself a write permission. File mode alone does not prevent replacement through a writable parent directory.
Formal Syntax & Structure
docker syntaxdocker
COPY --chown=<uid>:<gid> <source> <destination>Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| uid | string | Numeric user ID or supported user name. |
| gid | string | Numeric group ID or supported group name. |
| source | string | Source file. |
| destination | string | Destination path. |
Working Example
Example Snippetdocker
FROM busybox:1.37 AS prepareRUN printf "approved report\n" > /report.txt && chmod 400 /report.txtFROM busybox:1.37WORKDIR /appCOPY --from=prepare --chown=10001:10001 /report.txt /app/report.txtUSER 10001:10001CMD ["cat", "/app/report.txt"]