for-win icon indicating copy to clipboard operation
for-win copied to clipboard

SHELL does not quote the first argument

Open rgl opened this issue 9 years ago • 8 comments

Why do we need to quote the SHELL first argument? That is, I expected this to work:

SHELL ["C:/Program Files/PowerShell/powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

But it fails with:

==> default: Running C:\vagrant\examples\powershell\run.ps1...
==> default: building the image...
==> default: Sending build context to Docker daemon  17.41kB
==> default: Step 1/9 : FROM powershell:6.0.0-beta.6
==> default:  ---> 0b91ee424622
==> default: Step 2/9 : SHELL C:/Program Files/PowerShell/powershell.exe -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';
==> default:  ---> Running in ccdf3e0a0391
==> default:  ---> 467976e28b51
==> default: Removing intermediate container ccdf3e0a0391
==> default: Step 3/9 : WORKDIR /app
==> default:  ---> 6fe1b950ca82
==> default: Removing intermediate container b51c068b032d
==> default: Step 4/9 : COPY *.ps1 ./
==> default:  ---> 9faef9188b47
==> default: Step 5/9 : USER ContainerUser
==> default:  ---> Running in 1dbd0d9ac23c
==> default:  ---> c5d8a574b108
==> default: Removing intermediate container 1dbd0d9ac23c
==> default: Step 6/9 : RUN .\whoami.ps1
==> default:  ---> Running in 839f4b6e9c09
==> default: The argument 'Files/PowerShell/powershell.exe' is not recognized as the name of a script file. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

NB the full Dockerfile is at https://github.com/rgl/docker-windows-core-insider-2016-vagrant/blob/1c267e78a69937bbf107bd8a4c9136ecba0e56de/examples/powershell/info/Dockerfile#L2

If I quote the first argument, it works:

SHELL ["\"C:/Program Files/PowerShell/powershell.exe\"", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

I'm using:

==> default: Client:
==> default:  Version:      17.09.0-ce-rc1
==> default:  API version:  1.31
==> default:  Go version:   go1.8.3
==> default:  Git commit:   ae21824
==> default:  Built:        Wed Sep  6 22:25:14 2017
==> default:  OS/Arch:      windows/amd64
==> default: Server:
==> default:  Version:      17.09.0-ce-rc1
==> default:  API version:  1.32 (minimum version 1.24)
==> default:  Go version:   go1.8.3
==> default:  Git commit:   ae21824
==> default:  Built:        Wed Sep  6 22:35:40 2017
==> default:  OS/Arch:      windows/amd64
==> default:  Experimental: false

On windows server 2016 insider:

==> default: Microsoft Windows [Version 10.0.16278.1000]

rgl avatar Sep 09 '17 11:09 rgl

This behaviour has been a source of frustration for me as well. It seems like every command in the Dockerfile has double-quotes expanded before the command is run by the specified shell.

Is this an issue resulting from how Docker invokes commands on Windows or an expected behaviour that hasn't been documented clearly?

jmlane avatar Oct 16 '17 13:10 jmlane

There's a parser directive to control the escape character: https://github.com/dotnet/dotnet-docker/blob/master/2.0/sdk/nanoserver/amd64/Dockerfile#L1

Would that help?

friism avatar Oct 17 '17 07:10 friism

@friism It does not unfortunately.

# escape=`
FROM microsoft/powershell
SHELL ["powershell.exe", "-Command"]
...
RUN Write-Output \"contrived string interpolation: $env:var\"

You need to escape double-quotes with backslashes in exec RUN lines for the specified shell to receive them.

jmlane avatar Oct 17 '17 14:10 jmlane

There seems to be some dependency on base image here?

This works:

FROM microsoft/aspnetcore:2.0-nanoserver-sac2016

SHELL ["cmd", "/S", "/C"]

...snip...

RUN ["C:/Program Files/PowerShell/pwsh.exe", "C:/BaseImage/Configure-PowerShell.ps1"]

But here the escaping is required:

FROM microsoft/aspnetcore:2.0-nanoserver-1709

SHELL ["cmd", "/S", "/C"]

...snip...

RUN ["\"C:/Program Files/PowerShell/pwsh.exe\"", "C:/BaseImage/Configure-PowerShell.ps1"]

sandersaares avatar Feb 09 '18 15:02 sandersaares

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale comment. Stale issues will be closed after an additional 30d of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle stale

docker-robott avatar May 14 '18 08:05 docker-robott

this is not yet clear... so do not close.

/remove-lifecycle stale /lifecycle frozen

rgl avatar Jul 30 '18 21:07 rgl

Can someone please re-open this issue?

rgl avatar Jul 30 '18 21:07 rgl

Closed issues are locked after 30 days of inactivity. This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle locked

docker-robott avatar Jun 23 '20 03:06 docker-robott