使用以下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'
空间在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