4

I am trying to create a Dockerfile that adds a folder that I have somewhere on the my local windows filesystem to a windows container. However, I have trouble figuring out the correct syntax.

Specifically, I am trying to copy the contents of the directory [C:\Foo Source Files\Zog Foo\Bar] to [C:\Bar] on in the Windows Docker container.

Thus far, I have attempted the following variants:

ADD ["C:\Foo Source Files\Zog Foo\Bar", "C:/Bar"]
ADD ["C:\Foo Source Files\Zog Foo\Bar\", "C:/Bar/"]

These caused the following error when trying to run build the image:

failed to process "[\"C:\\Foo": unexpected end of statement while looking for matching double-quote

By contrast, the following variants...

ADD ["C:/Foo Source Files/Zog Foo/Bar", "C:/Bar"] 
ADD ["C:/Foo Source Files/Zog Foo/Bar/", "C:/Bar/"]
ADD ["C:\\Foo Source Files\\Zog Foo\\Bar\\", "C:/Bar/"]
ADD ["C:\\\\Foo Source Files\\\\Zog Foo\\\\Bar\\\\", "C:/Bar/"]
ADD ["C:\\\\Foo Source Files\\\\Zog Foo\\\\Bar", "C:/Bar/"]
ADD C:/Foo Source Files/Zog Foo/Bar/, C:/Bar/
ADD C:\Foo Source Files\Zog Foo\Bar\, C:/Bar/

...caused the following differing error:

ADD failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-builder997952273\Foo Source Files\Zog Foo\Bar: The system cannot find the path specified.

This variant...

ADD C:\Foo Source Files\Zog Foo\Bar\, C:/Bar/

...caused this slightly different error:

ADD failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-builder997952273\Foo: The system cannot find the path specified.

After that, I tried to drop rename my source folders so they didn't contain any whitespaces, and tried it with this statement:

ADD C:\FooSourceFiles\ZogFoo\Bar\, C:/Bar/

...but that only resulted in the following error again:

ADD failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-builder197358441\C:FooSourceFilesZogFooBar,: The system cannot find the file specified.

I also tried it with extra slashes as escape character...

ADD C:\\FooSourceFiles\\ZogFoo\\Bar\\, C:/Bar/

...but that also failed since apparently Docker is looking for the file in a subdirectory of the docker working directory, even though I tried to instruct it to look in an absolute path

ADD failed: CreateFile \\?\C:\ProgramData\Docker\tmp\docker-builder492157702\FooSourceFiles\ZogFoo\Bar\,: The system cannot find the path specified.

Any help with this would be greatly appreciated.

Edit: Explanation why this is not a duplicate of Dockerfile COPY instruction failing?: That question is about a COPY instruction failing that turned out to be because of "~/" not working, and it also is about Linux containers. My question is primarily about the correct syntax for using the ADD command on Windows containers. I don't see how these two issues are related, and the approved answer on that topic does not even apply to my case.

Kira Resari
  • 1,718
  • 4
  • 19
  • 50
  • 1
    There is some good gotchas about windows containers listed here. https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/manage-windows-dockerfile – Gregory Suvalian Sep 21 '18 at 11:31
  • In addition I would start all windows docker files with #escape = ` – Gregory Suvalian Sep 21 '18 at 11:44
  • Possible duplicate of [Dockerfile COPY instruction failing?](https://stackoverflow.com/questions/28057842/dockerfile-copy-instruction-failing) – David Maze Sep 24 '18 at 01:05

1 Answers1

7

Apparently, the problem was that Docker does not support absolute paths as input paths.

I was finally able to get it to work by putting the "Bar"-Folder in the same directory as the Dockerfile and then using the following ADD Statement in the Dockerfile:

ADD Bar C:/Bar/

If I am mistaken, and it is possible to use absolute paths as the source path, please correct me

Kira Resari
  • 1,718
  • 4
  • 19
  • 50
  • Seems like you are correct [https://stackoverflow.com/a/39667707/530634] – tjb Mar 01 '19 at 10:57
  • The source files for an ADD must be INSIDE the "context" as per doco: "The path must be inside the context of the build; you cannot ADD ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon" – TomB Oct 15 '19 at 20:08