docker for windows - How to read Powershell variable inside Dockerfile? -
i'm building docker windows image. try pass variable powershell command, not work.
dockerfile
# escape=` microsoft/windowsservercore shell ["powershell", "-command", "$erroractionpreference = 'stop'; $progresspreference = 'silentlycontinue';"] run $somevar="2.60.3" ; echo $somevar
docker build
sending build context docker daemon 2.048kb step 1/3 : microsoft/windowsservercore ---> 2c42a1b4dea8 step 2/3 : shell powershell -command $erroractionpreference = 'stop'; $progresspreference = 'silentlycontinue'; ---> using cache ---> ebd40122e316 step 3/3 : run $somevar="2.60.3" ; echo $somevar ---> running in dd28b74bdbda ---> 94e17242f6da removing intermediate container dd28b74bdbda built 94e17242f6da tagged secrets:latest
exprected result
i can workaround using env variable and, possibly, multistage build avoid keeping variable:
# escape=` microsoft/windowsservercore shell ["powershell", "-command", "$erroractionpreference = 'stop'; $progresspreference = 'silentlycontinue';"] env somevar="2.60.3" run echo $env:somevar sending build context docker daemon 2.048kb step 1/4 : microsoft/windowsservercore ---> 2c42a1b4dea8 step 2/4 : shell powershell -command $erroractionpreference = 'stop'; $progresspreference = 'silentlycontinue'; ---> using cache ---> ebd40122e316 step 3/4 : env somevar "2.60.3" ---> running in 8ac10815ff6d ---> 9073ec3256e0 removing intermediate container 8ac10815ff6d step 4/4 : run echo $env:somevar ---> running in 43a41df36f92 2.60.3 ---> 09e48901bea9 removing intermediate container 43a41df36f92 built 09e48901bea9 tagged secrets:latest
double-quotes need escaped them work expected, somevar=\"2.60.3\"
.
wiki
Comments
Post a Comment