Passing a private repository token as a build argument writes it into the image history, where docker history reads it back out for anyone who can pull the image.
# leaks, permanently
# ARG COMPOSER_AUTH
# RUN composer install
# mounted for one instruction, never written to a layer
RUN --mount=type=secret,id=composer_auth
COMPOSER_AUTH="$(cat /run/secrets/composer_auth)"
composer install --no-dev
# docker build --secret id=composer_auth,src=./auth.json .
Deleting the file in a later instruction does not help, because layers are additive and the earlier one still contains it. An SSH agent mount does the same job for a private git dependency, which is the other common case and the one usually solved by baking a deploy key into the image. Verifying with docker history --no-trunc | grep -i token is a two-second check that belongs in CI rather than in somebody’s memory.