使用以下docker-compose.yml,我总会收到无法解释的语法错误(我看不到两个docker-compose.ymls在第2行和第3行的区别)
---
version: '2'
services:
app-module:
container_name: app-module:
env_file: ./app-module:.env
image: registry.x/app/app-module:latest
network_mode: "bridge"
ports:
- "30303:30303"
volumes:
- type: volume
source: node-volume
target: /datadir
- ./data:/data
- ./log:/log
错误消息:
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./docker-compose.yml", line 2, column 1
expected <block end>, but found '<block mapping start>'
in "./docker-compose.yml", line 3, column 3
我看不到与其他工作文件的语法差异。
这就是我用来启发文件的docker-compose.yml:
---
version: '2'
services:
app-node:
container_name: app-node
env_file: ./app-node.env
image: registry.x/group/app-node:latest
network_mode: "bridge"
ports:
- "7990:7990"
- "7999:7999"
volumes:
- ./data:/data
- ./log:/log
证明:
$ docker-compose config
services:
app-node:
container_name: app-node
environment: {}
image: registry.x/group/app-node:latest
network_mode: bridge
ports:
- 7990:7990/tcp
- 7999:7999/tcp
volumes:
- ...app-node/Test/data:/data:rw
- ...app-node/Test/log:/log:rw
version: '2.0'
答案 0 :(得分:3)
YAML中的空格很重要。 services:
前面有两个不应存在的空格。您是在告诉YAML services
在version
中,但是version
已经有一个值。
这是两者之间的区别:
foo: bar
in_foo: bar
由于in_foo
位于foo
中而无法正常工作,并且:
foo: bar
not_in_foo: bar
之所以有效,是因为not_in_bar
不在foo
中。
或者,这将是有效的语法(但是docker-compose将会失败,因为它期望version
中有一个字符串):
version:
services:
foo: bar