user11578764
user11578764

Reputation:

How to use environment variables in Windows container with Powershell

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"}]}

Upvotes: 1

Views: 1957

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41545

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"}]}

Upvotes: 2

Related Questions