代码之家  ›  专栏  ›  技术社区  ›  Kira Resari

Dockerfile~添加Windows文件夹的正确语法

  •  1
  • Kira Resari  · 技术社区  · 7 年前

    我正在尝试创建一个Dockerfile,将本地windows文件系统中的某个文件夹添加到windows容器中。但是,我很难找出正确的语法。

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

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

    这些操作在尝试运行生成映像时导致以下错误:

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

    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/
    

    …导致了以下不同的错误:

    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/
    

    …导致了这个稍微不同的错误:

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

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

    …但这只会再次导致以下错误:

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

    我也试过用额外的斜杠作为转义符。。。

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

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

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

    任何帮助都将不胜感激。

    解释为什么这不是Dockerfile复制指令的副本失败?:

    1 回复  |  直到 7 年前
        1
  •  3
  •   Kira Resari    7 年前

    显然,问题是码头工人 作为输入路径。

    最后,我将“Bar”文件夹与Dockerfile放在同一目录下,然后在Dockerfile中使用以下ADD语句,使它能够正常工作:

    ADD Bar C:/Bar/
    

    可以使用绝对路径作为源路径,请更正我