Docker version: Docker version 20.10.17, build 100c701
OS: Windows 11 (21H2, Build 22000.795)
Using Windows Containers
I’m having trouble passing arguments that include whitespace.
Building the following Dockerfile:
# escape=` FROM mcr.microsoft.com/windows/servercore:ltsc2022 COPY ["myscript.bat", "C:\\Program Files (x86)\\myscript.bat"] ENTRYPOINT ["C:\\Program Files (x86)\\myscript.bat", "&&", "echo", "Good bye"]
works fine. Where myscript.bat is a single-line script echoing “Hello”.
Starting a container using that image yields the one and only error:
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
If I modify “Good bye” to “Goodbye” it works as expected and I get the following output:
Not sure how the spaces in the path to myscript suddenly becomes an issue when the second echo command’s argument contains a space. However, I’ve tried to quote the path in different ways, but that only results in errors like “The system cannot find the file specified” from System::CreateProcess.
It doesn’t seem to matter if the second “echo” command is placed in CMD or passed as command line arguments to docker run, I get the same ‘C:\Program’ is not recognized…’ error.
For context, in my real use case (where the bat script is vsdevcmd.bat from visual studio) the argument in question that contains a space is passed to docker run as a command line argument (via the win32 Windows CreateProcessW api, and quoted as part of the lpCommandLine argument). And the entrypoint of the image looks like this:
ENTRYPOINT ["C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat", “-arch=amd64”, “&&”, “powershell.exe”, “-NoLogo”, “-ExecutionPolicy”, “Bypass”]
But the effect seems to be the same, it complains about the path in the first entrypoint item when the space character is present in one of the arguments passed to docker run, and it works if I remove the space.
Any ideas how to solve this to be able to pass arguments containing spaces?