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
Related
Can somebody, please, help me to understand what's wrong with my docker-compose.yml file?
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
ports:
- "8080:8080"
volumes:
- "$PWD/jenkins_home:/var/jenkins_home"
networks:
- net
networks:
net:
I get an error:
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./docker-compose.yml", line 1, column 1
expected <block end>, but found '<block mapping start>'
in "./docker-compose.yml", line 2, column 3
Try the following. There seem to be multiple issues with your compose file.
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
ports:
- "8080:8080"
volumes:
- "$PWD/jenkins_home:/var/jenkins_home"
Note: If the following doesn't work, share the full docker-compose.yaml and the Docker compose version.
You should indent lines after services, so the correct form is:
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
ports:
- "8080:8080"
volumes:
- "$PWD/jenkins_home:/var/jenkins_home"
networks:
- net
networks:
net:
I am a newbie in the docker world and while doing some tutorials I encountered the following error:
yaml: line 1: did not find expected key
This is my .YAML file:
version: '3'
services:
mongodb:
image: mongo
ports:
-27017:27017
environment:
- MONGO-INITDB_ROOT_USERNAME=admin
- MONGO-INITDB_ROOT_PASSWORD=password
mongo-express:
image: mongo-express
ports:
-8080:8081
environment:
-ME_CONFIG_MONGODB_ADMINUSERNAME=admin
-ME_CONFIG_MONGODB_ADMINPASSWORD=password
-ME_CONFIG_MONGODB_SERVER=mongodb
I tried to search if there is a problem with the compatibility of the docker-compose & docker-engine but even though I tried to put other versions like 2/2.1/2.2/2.3/3/3.8 in the ".YAML" file I still get the same error message.
Docker Compose version v2.2.1 <br>
Docker Engine v20.10.11
Tried to look up some solutions but I was not able to find anything.
Your indentation is incorrect and some other spacing/syntax is also incorrect.
version: '3'
services:
mongodb:
image: mongo
ports:
- 27017:27017
environment:
- MONGO-INITDB_ROOT_USERNAME=admin
- MONGO-INITDB_ROOT_PASSWORD=password
mongo-express:
image: mongo-express
ports:
- 8080:8081
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=password
- ME_CONFIG_MONGODB_SERVER=mongodb
Here is my docker-compose yaml file.
version: '2.1'
services:
myservice:
environment:
- MYENVVAR={"1": "Hello"}
This gives me the following parsing error when I run docker-compose
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./my_docker_compose_.yml", line 6, column 9
expected <block end>, but found '}'
in "./my_docker_compose_.yml", line 6, column 111
How can I escape my JSON object properly so it gets sent into the container as the value of environment variable MYENVVAR?
You should define this variable as:
'FOOBAR={"foo": "bar"}'
In short:
version: '3.3'
services:
nginx:
ports:
- '80:80'
volumes:
- '/var/run/docker.sock:/tmp/docker.sock:ro'
restart: always
logging:
options:
max-size: 1g
environment:
- 'FOOBAR={"foo": "bar"}'
- a=test
image: nginx
The similar question was raised on docker bug tracking system:
https://github.com/docker/compose/issues/3878
You can validate or experiment with docker-compose settings online
by visiting a web page:
https://composerize.com/
This might be a completely lame question, but I was going through the different directive examples of docker-compose and a thought came to my mind.
Is there a syntax or a code-book that specifies the spacing syntax of the spacing that is written in docker-compose.yml? Different examples online show different spacing.
I know that tab is not allowed in docker-compose.yml, but for the spacing part, which of the below stands correct -
docker-compose.yml : Here the spacing is 2 spaces each, for the services, directives and their values (given using -)
version: "3.2"
services:
myservice:
image: mysql:5.5
container_name: contDEV
ports:
- target: 18530
published: 3306
volumes:
- type: bind
source: /app
target: /var
environment:
- MYSQL_USER=unpush
- MYSQL_PASSWORD=push
networks:
- cloud-nw
networks:
cloud-nw:
docker-compose.yml : Here the spacing is 2 spaces each, for the services and directives but their values (given using -) are written without space.
version: "3.2"
services:
myservice:
image: mysql:5.5
container_name: contDEV
ports:
- 18530:3306
volumes:
- type: bind
source: /app
target: /var
environment:
- MYSQL_USER=unpush
- MYSQL_PASSWORD=push
networks:
- cloud-nw
networks:
cloud-nw:
docker-compose.yml : Here the spacing is 4 spaces each, for the services and directives but their values (given using -) are written without space.
version: "3.2"
services:
myservice:
image: mysql:5.5
container_name: contDEV
ports:
- 18530:3306
volumes:
- type: bind
source: /app
target: /var
environment:
- MYSQL_USER=unpush
- MYSQL_PASSWORD=push
networks:
- cloud-nw
networks:
cloud-nw:
when i try to compose i get shown this:
yaml.scanner.ScannerError: mapping values are not allowed here
in "./docker-compose.yml", line 6, column 15
my docker-compose.yml:
version: '2'
services:
fhem:
restart:always
expose:
- "8083"
- "7072"
ports:
- "8083:8083"
- "7072:7072"
build: fhem
privileged: true
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"
....
can´t see any wrong syntax at all
You're missing a space after the colon following restart (per #bartimar), and your device line isn't indented correctly, since you're using 4 space indent.
version: '2'
services:
fhem:
restart: always
expose:
- "8083"
- "7072"
ports:
- "8083:8083"
- "7072:7072"
build: fhem
privileged: true
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"