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

NameTypeDescription
uidstringNumeric user ID or supported user name.
gidstringNumeric group ID or supported group name.
sourcestringSource file.
destinationstringDestination 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"]
Docker Reference