Command arguments with spaces issue

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=`


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?

I don’t know about Windows containers, but ths entrypoint wouldn’t work on Linux as the entrypoint must be a single command which will use the CMD as its argument. On Linux && means the second part has to run only if the first didn’t fail. But those characters on Linux work only in a shell which is not available when you are using the “exec form” which is exactly what you are using.

So again, I’m talking about Linux and Windows could be different, but on Linux, I would define one script in the entrypoint and in that script I could run a similar command to wha you want in the Windows container:

"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" “-arch=amd64” && “powershell.exe” “-NoLogo” “-ExecutionPolicy” “Bypass”

Of course since you don’T use any arguments here, I would indeed define it as a CMD not as an ENTRYPOINT, but the rule is the same.

This is about lLinux but could give you some hints