Dockerfile〜添加Windows文件夹的正确语法 [英] Dockerfile ~ Correct Syntax for Adding Windows Folders

查看:111
本文介绍了Dockerfile〜添加Windows文件夹的正确语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个Dockerfile,将本地Windows文件系统上某处的文件夹添加到Windows容器中.但是,我在弄清楚正确的语法时遇到了麻烦.

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.

具体地说,我正在尝试将目录[C:\ Foo Source Files \ Zog Foo \ Bar]的内容复制到Windows Docker容器中的[C:\ Bar].

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.

此变体...

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/

...但是这也失败了,因为显然Docker正在docker工作目录的子目录中查找文件,即使我试图指示它在绝对路径中查找

...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.

解释为什么这不是Dockerfile COPY指令失败的重复项?:该问题与COPY指令失败有关,该问题原来是由于〜/"不起作用,并且也与Linux容器有关.我的问题主要是关于在Windows容器上使用ADD命令的正确语法.我看不到这两个问题之间的关系,有关该主题的已批准答案甚至不适用于我的情况.

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.

推荐答案

显然,问题在于Docker 不支持绝对路径作为输入路径.

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

通过将"Bar"文件夹放置在与Dockerfile相同的目录中,然后在Dockerfile中使用以下ADD语句,我终于能够使它工作:

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

这篇关于Dockerfile〜添加Windows文件夹的正确语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆