Docker Community Forums

Share and learn in the Docker community.

Exception when building simple Dockerfile with Windows Containers

I must be doing something fundamentally wrong, but I can’t seem to figure it out.

I have Docker Desktop 3.5.2 installed on a Windows 10 Enterprise machine (20H2), using the WSL 2 engine. I had been working with Linux containers and was able to build images and run containers without a problem.

I wanted to start working with Windows containers, so I right-clicked the Docker icon in the system tray and selected “Switch to Windows containers…”. I created a simple Dockerfile:

RUN echo "Hello World 1"
RUN echo "Hello World 2"

If I execute:
docker build -t test -f "./Dockerfile" .

I get the following output:

Sending build context to Docker daemon  3.072kB
Step 1/3 : FROM
20H2: Pulling from windows/nanoserver
d33d999f2c9c: Pull complete
Digest: sha256:1eaf8acfc9f6bad4035fdf663873b685ad654d27bf30cc056a0a2af74b922c4d
Status: Downloaded newer image for
 ---> 695bc2c82a9f
Step 2/3 : RUN echo "Hello World 1"
 ---> Running in fe3334e5e10d
"Hello World 1"
re-exec error: exit status 1: output: hcsshim::ImportLayer - failed failed in Win32: The system cannot find the path specified. (0x3)

I suspected it might be due to the WSL 2, but the same thing happens if I disabled the WSL 2 and use Hyper-V instead.

Any suggestions?

I guess the answer is simply that there is no separate echo executable on windows (different to Linux). echo is part of cmd.exe, so you have to use

RUN cmd.exe /C echo “Hello world 1”

The error message from docker hints into completely different direction, so I’m not sure. Please give it a try. Docker error messages are quite often not really to the point.

Thanks for the suggestion.

It doesn’t seem to be a problem with the command itself – both RUN cmd.exe /C echo “Hello world 1” and RUN echo "Hello World 1" appear to execute correctly (i.e. “Hello World 1” appears in the output before I see the error message).

And I see the same thing if I run another command like RUN cmd.exe /C dir or RUN dir. The output shows that the command ran fine (in this case, printing the directory contents), but it terminates with the error message and never gets to the next command.

It must be something really dumb, but I’m missing it…