Dockerfile instructions

RUN cache mount

BuildKit mount for reusable scratch files; not part of the committed filesystem. Correctness must tolerate empty or stale cache. locked coordinates writers. A prior marker can be stale; neither locking nor no-cache guarantees a clean mount.

Formal Syntax & Structure

docker syntaxdocker
RUN --mount=type=cache,target=<path>[,id=<id>][,sharing=locked] <command>

Parameters & Attributes

NameTypeDescription
targetstringMount path.
idstringCache identity.
sharingstringConcurrency mode.

Working Example

Example Snippetdocker
FROM busybox:1.37ARG REV=oneRUN --mount=type=cache,id=bm-v09-scratch,target=/scratch,sharing=locked \    if [ ! -f /scratch/marker ]; then printf "ready\n" > /scratch/marker; fi; \    cat /scratch/marker > /result.txt; printf "%s\n" "$REV" >> /result.txtCMD ["cat", "/result.txt"]
Docker Reference