So I was very excited to see native Docker support in Windows Server 2016. I created a Dockerfile similar to the following and ran into a bit of trouble:
# escape=` FROM microsoft/nanoserver SHELL ["powershell", "-Command"] RUN Add-Content C:\path\to\file.txt "This is my message"
It exploded because of the quotes. This is the output:
docker build . Sending build context to Docker daemon 2.048 kB Step 1/3 : FROM microsoft/nanoserver ---> e14bc0ecea12 Step 2/3 : SHELL powershell -Command ---> Running in 69e4802ba983 ---> ef2271e9628a Removing intermediate container 69e4802ba983 Step 3/3 : RUN Add-Content C:\path\to\file.txt "This is my message" ---> Running in ed88985731db Add-Content : A positional parameter cannot be found that accepts argument 'is'. At line:1 char:1 + Add-Content C:\path\to\file.txt This is my message + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Add-Content], ParameterBin dingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell .Commands.AddContentCommand The command 'powershell -Command Add-Content C:\path\to\file.txt "This is my message"' returned a non-zero code: 1
What can be done about this? I can escape the quotes, but it’s ugly and feels like I shouldn’t need to do that. Single quotes aren’t always an option because I’d like to make use of string interpolation.
Any pointers / tips?
EDIT: Interestingly, the Dockerfile reference for the SHELL command switches from using double quotes to single quotes in its examples. Is this a known issue?