Dockerfile:COPY/ADD路径中带有空格字符(Windows) [英] Dockerfile: COPY / ADD with space character in path (Windows)

查看:150
本文介绍了Dockerfile:COPY/ADD路径中带有空格字符(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows 10(cmd)中,我正在尝试从子文件夹中复制文件,该子文件夹的名称中包含空格字符.

In Windows 10 (cmd) I'm trying to copy a file from a subfolder containing a space character in its name.

  1. 首先,我尝试使用引号:

  1. First I tried to use quotation marks:

FROM jfloff/alpine-python:2.7
COPY "Folder 1/File.txt" "Dir 1"

错误消息:

无法处理"\"文件夹":查找匹配的双引号时语句意外结束

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

  • "JSON"格式(跳过第一行):

  • "JSON" format (skipped the first line):

    COPY ["Folder 1/File.txt" "Dir 1"]
    

    错误消息:

    无法处理"[\"文件夹":查找匹配的双引号时语句意外结束

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

  • 尝试使用单个反斜杠进行转义:

  • Trying to escape with a single backslash:

    COPY "Folder\ 1/File.txt" "Dir\ 1"
    

    错误消息:

    无法处理"\"文件夹\\":查找匹配的双引号时语句意外结束

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

  • 试图以双反斜杠转义:

  • Trying to escape with a double backslash:

    COPY "Folder\\ 1/File.txt" "Dir\\ 1"
    

    错误消息:

    无法处理"\"文件夹\\\\":查找匹配的双引号时语句意外结束

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

  • 还尝试了使用%20 代替空格的建议:

    COPY ["Folder%201/File.txt" "Dir%201"]
    

    错误消息:

    复制失败:没有源文件

    COPY failed: no source File

  • 转义符替换:

  • Escape character replacement:

    # escape=`
    COPY "Folder` 1/File.txt" "Dir 1"
    

    错误消息:

    无法处理"\" Folder`":查找匹配的双引号时语句意外结束

    failed to process "\"Folder`": unexpected end of statement while looking for matching double-quote

  • 相同,但没有引号:

  • The same, but without quotes:

    #escape=`
    COPY Folder` 1/File.txt Dir` 1
    

    错误消息:

    复制失败:stat/var/lib/docker/tmp/docker-builder082039614/文件夹:没有此类文件或目录

  • 使用 tar 归档文件打包/解包的方法(我对该想法不满意).

  • Method with packing / unpacking using a tar archive (I'm not happy with that idea).

    应该有可能,不是吗?

    推荐答案

    也许您可以使用 ARG 来帮助您,就像这样:

    Maybe you can use ARG to help you, like this:

    Dockerfile:

    FROM jfloff/alpine-python:2.7
    ARG src="Folder 1/File.txt"
    ARG target="Dir 1/"
    COPY ${src} ${target}
    

    顺便说一句,如果您真的想将其视为文件夹,则必须在 Dir 1 的末尾添加/.

    BTW, a / has to be add at the end of Dir 1 if you treat really want to treat it as a folder.

    而且,JSON格式也可以,只要您错过,它应该是:

    And, JSON format is also ok, just you miss ,, it should be:

    FROM jfloff/alpine-python:2.7
    COPY ["Folder 1/File.txt", "Dir 1/"]
    

    更新您的评论:

    官方指南中,它说:

    复制包含特殊字符(例如[和])的文件或目录时,需要遵循Golang规则转义那些路径,以防止将它们视为匹配模式.

    When copying files or directories that contain special characters (such as [ and ]), you need to escape those paths following the Golang rules to prevent them from being treated as a matching pattern.

    因此,对于您的情况,应该是:

    So, for your case, it should be:

    FROM jfloff/alpine-python:2.7
    ARG src="[[]Folder 1]/__SLIM_TEMPLATE.mm"
    ARG target="[Folder 1]/"
    COPY ${src} ${target}
    

    或者:

    FROM jfloff/alpine-python:2.7
    COPY ["[[]Folder 1]/__SLIM_TEMPLATE.mm", "[Folder 1]/"]
    

    这篇关于Dockerfile:COPY/ADD路径中带有空格字符(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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