Unable to consume ARG or ENV variables in RUN commands

A simple test works for me:

C:\code\repros\win-arg-env> cat .\Dockerfile
FROM microsoft/nanoserver

SHELL ["powershell", "-command"]

ARG foo=bar

RUN echo $Env:foo
C:\code\repros\win-arg-env> docker build --no-cache -t win-arg-env .
Sending build context to Docker daemon 2.048 kB
Step 1/4 : FROM microsoft/nanoserver
 ---> 787d9f9f8804
Step 2/4 : SHELL powershell -command
 ---> Running in 561248e5b034
 ---> 3f3d73723742
Removing intermediate container 561248e5b034
Step 3/4 : ARG foo=bar
 ---> Running in b5fc507ca1fa
 ---> 36bc6bf2763e
Removing intermediate container b5fc507ca1fa
Step 4/4 : RUN echo $Env:foo
 ---> Running in 44674c5c5d65
bar
 ---> 53fdcd8ad1ba
Removing intermediate container 44674c5c5d65
Successfully built 53fdcd8ad1ba
2 Likes