I am attempting to consume ARG or ENV variables from a RUN or CMD statement on Docker in Windows Server 2016, but no matter what I try, the variable is never interpolated. Take this Dockerfile for example:
FROM microsoft/windowsservercore
ARG azureArchive="Microsoft.Azure.ServiceFabric.WindowsServer.5.3.311.9590.zip"
SHELL ["powershell", "-command"]
# This works, ${azureArchive} is interpolated to the above value
ADD ${azureArchive} /
# This one doesn't, ${azureArchive} is always treated literally
RUN Expand-Archive ${azureArchive} $env:temp\AzureServiceFabric
# additionally, how can I set WORKDIR from a Powershell variable?
#WORKDIR $env:temp\AzureServiceFabric
I’ve tried this with both Powershell and CMD- the result is the same. Any help would be greatly appreciated.
Okay clearly I misunderstood something here. You’re accessing the Dockerfile ARG “foo” from $env:foo, instead of $foo. $env is Powershell, so how’d it get populated? Is that what ARG is actually doing: populating a Shell variable?
I just tried the same script using the default Windows shell and I was able to echo %foo%. I thought it was Docker performing the substitution. Rather, Docker just exposes the variable to the current shell.