Docker Community Forums

Share and learn in the Docker community.

ENV/ARG do not expand in the dst field in secrets mounting

The steps to reproduce will explain better than words. Let’s assume this simple Dockerfile:

FROM debian:10
RUN --mount=type=secret,id=mySecret,dst=/root/${MYVAR}.txt cat /root/${MYVAR}.txt

And building it using:

DOCKER_BUILDKIT=1 docker build \
    --secret id=mySecret,src=./mySecret.txt \
    --no-cache \

$MYVAR does not get expanded inside dst=. So the above does not work, but replacing ${MYVAR} in dst=/root/${MYVAR}.txt by its value myvar works fine.

I am running docker 20.10.6 on Ubuntu 20.04.2 LTS.