buildx
buildx copied to clipboard
automatically substitute system environment variables in Dockerfile during the build
I'm not sure if this will be a bug report or feature request but at least on Windows I cannot get automatic environment variable substitution to work in a Dockerfile which is executed by docker buildx build .
or docker build .
commands.
I tried multiple configurations:
ARG NPM_AUTH_TOKEN
ENV NPM_AUTH_TOKEN=${NPM_AUTH_TOKEN}
ARG NPM_AUTH_TOKEN=${NPM_AUTH_TOKEN}
ENV NPM_AUTH_TOKEN=${NPM_AUTH_TOKEN}
ARG NPM_AUTH_TOKEN=${NPM_AUTH_TOKEN}
The only thing to be working is if I add docker-compose.yaml file with contents:
services:
mydefaultbuild:
build:
args:
NPM_AUTH_TOKEN: ${NPM_AUTH_TOKEN}
Then if I run docker buildx bake
substitution starts to work.
Is this a bug? If not, it would be great if environment variable substitution would work out of the box without needing to remap variables in compose file.
build
command does not pass your client side environment variables to the dockerfile. They need to be passed with --build-arg
https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg
I know that it doesn't pass them. My question was different, is this a bug or this issue can be converted to feature request so that env. variables will be passed automatically?
add .env file
cat .env
NPM_AUTH_TOKEN=<yourToken>
docker-compose -f docker-compose.yaml up