Variable interpolation doesn't work in options?

In a Dockerfile that is reused among a number of projects, we use a variable to make it easier to replace the name of the project and its directories. So we have for example:
ARG APP_NAME=myapp
COPY --from=builder app/$APP_NAME-web/target/$APP_NAME*.jar app.jar

But the following command is not working
COPY --exclude=$APP_NAME-web/src/frontend . .
unless I leave the app name static like this:
COPY --exclude=myapp-web/src/frontend . .
then it successfully excludes the dir.

I don’t know if that’s a bug specifically with the --exclude option from docker/dockerfile:1.7-labs version or if variable interpolation doesn’t work in options arguments in general.

Docker version 28.0.1, build 068a01e on linux fedora silverblue 41

1 Like

I’m not entirely sure which options support build arguments if any, but it is true that variables are not supported everywhere. As a workaround, I would try a pattern that matches names ending with “-web” or you can also generate the Dockerfile using a template system which could also be a simple bash script using “envsubst”.

Since I think it is more likely that it is not a bug, you can try asking for supporting it in the roadmap

1 Like