I want to pass env variables from my Powershell on Windows to a Powershell script inside my Docker Image.
From my Windows Powershell I defined them like this:
$env:MY_VAR = 'test'
$env:MY_VAR2 = 'test2'
Then in my Docker image I have this:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
# some other stuff...
ADD run.ps1 /
ENTRYPOINT ["powershell", "/run.ps1"]
And my run.ps1 script is just:
gci env:* | sort-object name
echo $env:MY_VAR
echo $env:MY_VAR2
I tried something like this:
docker run -t my-image:latest -e $env:MY_VAR=$env:MY_VAR -e $env:MY_VAR2=$env:MY_VAR2
or:
docker run -t my-image:latest -e MY_VAR=$env:MY_VAR -e MY_VAR2=$env:MY_VAR2
My env variables are always empty, I don't find the right syntax where is the mistake ?