1

In a Windows docker container I'm trying to set an environment variable based on a build argument.

I have tried this:

docker build --build-arg MYVAR="test" .

In the Dockerfile I have:

#escape=`

ARG MYVAR
ENV MYENVVAR {`"endpointCredentials`": [{`"password`": `"$Env:MYVAR`"}]}

But when I run Get-Item $Env:MYVAR I get:

{"endpointCredentials": [{"password":":MYVAR"}]}

What I want is

{"endpointCredentials": [{"password":"test"}]}

1 Answer 1

2

The --build-arg is to pass arguments to the Dockerfile, so you need to configure the MYVAR as an argument in the Dockerfile:

ARG MYVAR
ENV MYENVAR {`"endpointCredntials`": [{`"password`": "$MYVAR"}]}
Sign up to request clarification or add additional context in comments.

2 Comments

I already had ARG MYVAR in my Dockerfile, I just forgot to mention it. Question updated.
But in the second line don't use $Env:MYVAR, just use $MYVAR or ${MYVAR}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.