docker-compose.yml content-如何避免“必须是映射而不是字符串"错误信息? [英] docker-compose.yml content - How can i avoid "must be a mapping not a string" error message?
问题描述
问题:以下内容返回服务'image'必须是映射而不是字符串".我尝试使用YAML分析器( http://yaml-online-parser.appspot.com/),但未返回任何错误.
Problem: the below content returns "service 'image' must be a mapping not a string." I tried using YAML Parser(http://yaml-online-parser.appspot.com/), but it returned no error.
version:
"2.0"
services:
blog:
image:
abc/defg
environment:
APPLICATION_SECRET:
82xxxxxxx
ports: -"9000:9000"
工作版本:
version: "2.1"
services:
blog:
image: abc/defg
environment:
APPLICATION_SECRET:
82xxx
ports:
- "9000:9000"
networks:
default:
external:
name: nat
推荐答案
If you look at the Python output that you get from the online parser, you can see that you get
'ports': '-"9000:9000"'
看起来不像端口号列表.
which doesn't look like a list of port numbers.
序列元素由一个破折号和一个空格表示,如果您在破折号后的 ports
之后输入该空格:
A sequence element is indicated by a dash followed by a space, and if you input that space after the dash following ports
:
ports: - "9000:9000"
您实际上确实会出错,因为作为值的块序列不能在键之后开始,而必须在它们自己的一行上开始:
You actually do get an error, as block sequences that are values cannot start after the key, but must start on a line of their own:
ports:
- "9000:9000"
尽管序列中的元素必须缩进,但连字符不一定必须缩进,只需将其与元素分隔至少一个空格即可.
Although the element in the sequence have to be indented, the dash doesn't have to be, it just needs to be separated from the element by at least one space.
这篇关于docker-compose.yml content-如何避免“必须是映射而不是字符串"错误信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!