Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell错误:重定向运算符后缺少文件规范_Powershell_Docker - Fatal编程技术网

Powershell错误:重定向运算符后缺少文件规范

Powershell错误:重定向运算符后缺少文件规范,powershell,docker,Powershell,Docker,我刚开始学习Docker教程,下载后按照官方主页上的命令进行操作 PS C:\COCcal> cat > Dockerfile <<EOF >> FROM busybox >> CMD echo "Hello world! This is my first Docker image." >> EOF PS C:\COCcal>cat>busybox的Dockerfile >>CMD echo“你好,世界!这是我的第一张Docker图片

我刚开始学习Docker教程,下载后按照官方主页上的命令进行操作

PS C:\COCcal> cat > Dockerfile <<EOF
>> FROM busybox
>> CMD echo "Hello world! This is my first Docker image."
>> EOF
PS C:\COCcal>cat>busybox的Dockerfile
>>CMD echo“你好,世界!这是我的第一张Docker图片。”
>>EOF
给我

At line:1 char:19
+ cat > Dockerfile <<EOF
+                   ~
Missing file specification after redirection operator.
At line:1 char:18
+ cat > Dockerfile <<EOF
+                  ~
The '<' operator is reserved for future use.
At line:1 char:19
+ cat > Dockerfile <<EOF
+                   ~
The '<' operator is reserved for future use.
At line:2 char:1
+ FROM busybox
+ ~~~~
The 'from' keyword is not supported in this version of the language.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingFileSpecification
第1行字符:19

+cat>Dockerfile没有您似乎正在PowerShell中运行Linux shell命令。根据您的配置,这可能会有问题。我建议打开Linux shell或使用PowerShell支持的命令

# Run the Set-Content Command Below
Set-Content -Path Dockerfile

# After Running the above command, I am prompted to enter data:
Value[0]: FROM busybox
Value[1]: CMD echo "Hello world! This is my first Docker image."
Value[2]:
运行上述命令时,系统将提示您输入
值[0]
值[1]
等(前提是在每行输入数据后按Enter键),直到在没有任何其他输入的行上按Enter键为止。每个输入都将位于
Dockerfile
中的单独一行

关于PowerShell中的操作员,仅支持
>
&1
。如果
cat
完全起作用,那是因为它是一个别名。您可以运行
Get Alias cat
,查看它映射到哪个命令。在我的系统上,这是
获取内容


如果您不需要具有Linux命令提供的相同经验,那么还有其他PowerShell方法可以完成此任务。下面只是一个例子

$Content = @'
line 1 stuff
line 2 stuff
line 3 stuff
'@
$Content | Set-Content -Path Dockerfile
有关使用
UTF8NoBOM
编码进行输出的信息,请参见下文

$Content = @'
line 1 stuff
line 2 stuff
line 3 stuff
'@
[IO.File]::WriteAllLines('C:\COCcal\Dockerfile',$Content,[Text.UTF8Encoding]::new($false))

我不能就Docker运行此Docker配置。因此,当尝试运行本机PARKESER命令时,可能需要考虑一些事情。

  • 如果
    Dockerfile
    要求显示某些行尾字符,则可以在Docker不喜欢的每行上使用回车符和换行符的组合
  • Docker可能期望某种编码为
    Dockerfile
    。虽然
    Set Content
    确实提供了
    -Encoding
    参数,但它仍然可能无法提供您所需要的。例如,您可以使用
    -编码UTF8
    。在Windows PowerShell中,这将是带有BOM的UTF8(在Windows PowerShell中,此命令没有无BOM选项)。Windows PowerShell中的默认编码将是
    default
    ,很可能是
    ANSI
    。在PowerShell Core中,默认编码为
    UTF8NoBOM

  • 这些是linux shell命令,而不是PowerShell命令。为什么要在PowerShell中运行它们?如果确实要在PowerShell中执行此操作,只需使用
    设置内容Dockerfile
    ,然后在提示下输入数据。要关闭文件时,只需在空行上按Enter键。