With the following docker-compose.yml I always get a syntax error I can't explain (I don't see the difference in lines 2 and 3 between the two docker-compose.ymls)
---
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 message:
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
I don't see any syntax differences to other working files.
That's the working docker-compose.yml I used as the inspiration of my file:
---
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
Proof:
$ 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'
Spaces matter in YAML. You have two spaces before services: that are not supposed to be there. You're telling YAML that services is in version but version already has a value.
It's the difference between:
foo: bar
in_foo: bar
which will not work because in_foo is in foo, and:
foo: bar
not_in_foo: bar
that will work because not_in_bar is not in foo.
Alternatively, this would be valid syntax (but then docker-compose will fail because it expects a string in version):
version:
services:
foo: bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With