我想在构建docker镜像并使用以下命令时在C驱动器中创建文件

RUN mkdir "C:\Program Files\Microsoft Passport RPS"

但这会引发错误:
Step 6/6 : RUN mkdir "C:\Program Files\Microsoft Passport RPS"
 ---> Running in ab58c6f2948d
[91mmkdir : A positional parameter cannot be found that accepts argument 'Files\Microsoft'.
At line:1 char:76
+ ... e = 'SilentlyContinue'; mkdir C:\Program Files\Microsoft Passport RPS
[0m[91m+                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[0m[91m    + CategoryInfo          : InvalidArgument: (:) [mkdir], ParentContainsErro
[0m[91m   rRecordException
+ FullyQualifiedErrorId : PositionalParameterNotFound,mkdir

尝试以上命令使用正斜杠和反斜杠。

我已经尝试了多个其他命令,如下所示:
ENV PATH_WITH_SPACE "C:/Program Files/Microsoft Passport RPS"
RUN mkdir $[PATH_WITH_SPACE]

RUN mkdir ["C:\Program Files\Microsoft Passport RPS"]

您能以适当的命令帮助我吗?

最佳答案

遇到了同样的问题。没有答案对我有用。
我终于通过使用`转义空间来使其工作

RUN mkdir "C:\Program` Files\Microsoft` Passport` RPS"
COPY . "C:\Program` Files\Microsoft` Passport` RPS"

另一种方法是使用Shell,并明确声明转义

While the JSON form is unambiguous and does not use the un-necessary cmd.exe, it does require more verbosity through double-quoting and escaping. The alternate mechanism is to use the SHELL instruction and the shell form, making a more natural syntax for Windows users, especially when combined with the escape parser directive
# escape=`

FROM microsoft/nanoserver
SHELL ["powershell","-command"]
RUN New-Item -ItemType Directory C:\Example
ADD Execute-MyCmdlet.ps1 c:\example\
RUN c:\example\Execute-MyCmdlet -sample 'hello world'

关于docker - 无法在目录名称中包含空格的Dockerfile中执行RUN mkdir,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52106820/

10-16 16:46
查看更多