"Error: The directory name is invalid" when setting --workdir for nanoserver image

I am experiencing issues setting the working directory and was hoping for some guidance. The strange thing is that the command I am using works with windowsservercore and fails with nanoserver, so I’m trying to wrap my head around what might be going on.

The following example (windowsservercore) is working:

C:\Users\Administrator> docker volume create foo
C:\Users\Administrator> docker run --workdir=c:\\gopath\\src\\github.com --volume=foo:c:/gopath/src/github.com microsoft/windowsservercore:1803
Microsoft Windows [Version 10.0.17134.165]
(c) 2018 Microsoft Corporation. All rights reserved.


The same command using nanoserver is failing:

C:\Users\Administrator> docker volume create foo
C:\Users\Administrator> docker run --workdir=c:\\gopath\\src\\github.com --volume=foo:c:/gopath/src/github.com microsoft/nanoserver:1803

docker: Error response from daemon: container 29d67676580dd316cafb0a993c4a304738136eb8eae06a69dcd8c688a6944466 encountered an error during CreateProcess: failure in a Windows system call: The directory name is invalid. (0x10b) extra info: {"ApplicationName":"","CommandLine":"c:\\windows\\system32\\cmd.exe","User":"ContainerUser","WorkingDirectory":"c:\\\\gopath\\\\src\\\\github.com","Environment":{},"EmulateConsole":false,"CreateStdInPipe":true,"CreateStdOutPipe":true,"CreateStdErrPipe":true,"ConsoleSize":[0,0]}.

I am testing with the following Windows Server images (vanilla, no changes):

  • Microsoft Windows Server 1803 with Containers (official Amazon AMI)
  • Windows Server version 1803 Datacenter Core for Containers (official Google Cloud Image)

Operating system:

Microsoft Windows [Version 10.0.17134.165]

Docker version:

C:\Users\Administrator>docker version
 Version:      17.06.2-ee-15
 API version:  1.30
 Go version:   go1.8.7
 Git commit:   64ddfa6
 Built:        Mon Jul  9 23:33:36 2018
 OS/Arch:      windows/amd64

Note that I also upgraded to 18.03 with the same results.

In case anyone runs into the same issue it appears to be caused by the fact that nanoserver is running as an unprivileged user and cannot use the drive as the working directory. Here is the post for reference that helped explain the issue:

This post had the answer I was looking for:

This could be solved with the following changes, depending on your security requirements:

FROM microsoft/nanoserver:1803
+USER ContainerAdministrator
ADD release/windows/amd64/drone-slack.exe /drone-slack.exe
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ENTRYPOINT [ "\\drone-slack.exe" ]