Search code examples
dockerdocker-composecontainersdocker-container

Why is "docker run mcr.microsoft.com/windows/servercore:1809 echo hello" giving me cannot find the file specified?


Simply put, running docker run mcr.microsoft.com/windows/servercore:1809 echo hello on a basic windows server core image gives me the following error:

docker: Error response from daemon: container b4e3e78ec07637c061407e28a24065d723ae20e1ef325c7c71fd3e40e06cdf58 encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)
[Event Detail:  Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail:  Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(173)\vmcomputeagent.exe!00007FF644139FAB: (caller: 00007FF6440EE19A) Exception(2) tid(394) 80070002 The system cannot find the file specified.
    CallContext:[\Bridge_ProcessMessage\VmHostedContainer_ExecuteProcess]
 Provider: 00000000-0000-0000-0000-000000000000].

What could be causing this issue? If I add "cmd" before the echo hello it doesn't give an error anymore, but I do not see that the command was executed. I only see C:\ being printed.


Solution

  • You need to run echo hello on cmd, because directly the system think that echo is an executable, when actually the echo is a command of cmd on windows. For example you can't execute echo from Task Scheduler, but you can run cmd from it.

    Summary, you can run the container with the command below:

    docker run mcr.microsoft.com/windows/servercore:1809 cmd /c echo Hello
    

    The command above will run cmd with the command echo Hello as you wanted.

    See the evidency:

    examples with erro and without error