docker扩展字段解析器错误 [英] docker extension fields Parser Error

查看:114
本文介绍了docker扩展字段解析器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚看到了新的 扩展字段 在Docker Compose v3.4中,并尝试与部分覆盖结合使用。

I just saw the new extension fields in Docker Compose v3.4 and tried to use it in combination with partially override.

我的撰写文件如下:

version: '3.4'

x-environment:
  &default-environment
  - FOO=foo
  - BAR=bar

services:
  myservice:
    [...]
    environment:
      << : *default-environment
      - BAZ=baz

当我尝试运行它时,我得到:

When I try to run it, I get:

ERROR: yaml.parser.ParserError: while parsing a block mapping
expected <block end>, but found '-'

(对于我的行 << ;: *默认-环境

有什么想法吗?

推荐答案

您尝试将合并键(为过时的YAML版本1.1指定)与序列一起使用。这不能用,因为合并键不是新语法,而只是可以在映射中使用的特殊键。

You are trying to use the merge key (specified for outdated YAML version 1.1) with sequences. This cannot work since the merge key is not a new syntax, but merely a special key that can be used in mappings.

当解析器解析<$ c的内容时$ c> environment ,它首先看到以下一行:

When the parser parses the content of environment, it sees this line first:

<< : *default-environment

此行包含一个隐式键,<< ; ,以及该键的值 * default-environment 。因此,解析器决定 environment 的值是一个映射。

This line contains an implicit key, <<, and a value for that key, *default-environment. Thus, the parser decides that the value of environment is a mapping.

现在在下一行,解析器遇到-,它是序列项的指示符。由于解析器当前正在解析映射,因此它无法处理序列项指示符,因此会因错误而停止。

Now on the next line, the parser encounters a -, which is an indicator for a sequence item. Since the parser is currently parsing a mapping, it cannot handle a sequence item indicator and thus stops with an error.

请注意,当前YAML版本未定义合并键1.2,并将在即将发布的1.3版本中明确弃用。因此,一般不建议使用。而且,正如您所发现的那样,无法将其与序列一起使用。

Note that the merge key is not defined for current YAML version 1.2 and will be explicitly deprecated for the upcoming 1.3 version. Therefore, its usage is discouraged in general. Moreover, there is no way of using it with sequences, as you discovered.

这篇关于docker扩展字段解析器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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