Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix my docker-compose.yml? - expected <block end>, but found '<block mapping start>'

Tags:

docker

yaml

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 

It seems there is an indentation issue in my yml file. I read some other questions on here, and tried various indentation schemes. I still cannot get it to work. I purposely removed the env names/pws before posting this question.

version: '2'   ghost:     image: ghost:latest     container_name: ghost-blog  #Specify a custom container name, rather than a generated default name.     environment:       - NODE_ENV=production       - MYSQL_DATABASE=db-name # Change {{db-name}}       - MYSQL_USER=user # Change {{username}}       - MYSQL_PASSWORD=pass # Change {{db-password}}       # - "MAILGUN_USER={{mailgun-user}}" # Change {{mailgun-user}}       # - "MAILGUN_PASSWORD={{mailgun-password}}" # Change {{mailgun-password}}     volumes:       - ./ghost:/var/lib/ghost # persist the data     ports:       - 2368:2368     depends_on:       - mysql # ensure that the database will start first     restart: always    mysql:     image: mysql:latest     container_name: ghost-db     environment:       - MYSQL_DATABASE=dbname # Change {{db-name}}       - MYSQL_ROOT_PASSWORD=db-pass # Change {{root-password}}       - MYSQL_USER=user # Change {{username}}       - MYSQL_PASSWORD=sq-pass # Change {{db-password}}     volumes:       - ./db:/var/lib/mysql     restart: always 
like image 390
JAstuccio Avatar asked Oct 16 '17 11:10

JAstuccio


People also ask

How do I validate a docker compose file?

Validating your file now is as simple as docker-compose -f docker-compose. yml config . As always, you can omit the -f docker-compose. yml part when running this in the same folder as the file itself or having the COMPOSE_FILE environment variable pointing to your file.

How do I run Docker compose yml in terminal?

To run and open . yml files you have to install Docker Compose. After the installation, go to your docker-compose. yml directory and then execute docker-compose up to create and start services in your docker-compose.

Where is Docker compose yml located?

The default path for a Compose file is ./docker-compose.yml .


2 Answers

In the future, you could use this website to check what is wrong with it and then fix it on the go.

EDIT:

So the problems you had with your docker-compose file were as follows:

  1. You didn't add services: after the version and

  2. You don't have to pass the :latest tag if you want the latest image, you will pass the tag when you want a specific version of the image and that's done between " "


As for the code, it should be as follows:

version: '2'  services:       ghost:         image: ghost         container_name: ghost-blog         environment:           - NODE_ENV=production           - MYSQL_DATABASE=db-name           - MYSQL_USER=user           - MYSQL_PASSWORD=pass       #   - "MAILGUN_USER={{mailgun-user}}"       #   - "MAILGUN_PASSWORD={{mailgun-password}}" # Change {{mailgun-password}}         volumes:          - ./ghost:/var/lib/ghost # persist the data         ports:           - 2368:2368         depends_on:           - mysql # ensure that the database will always start first         restart: always        mysql:         image: mysql         container_name: ghost-db         environment:           - MYSQL_DATABASE=dbname # Change {{db-name}}           - MYSQL_ROOT_PASSWORD=db-pass # Change {{root-password}}           - MYSQL_USER=user # Change {{username}}           - MYSQL_PASSWORD=sq-pass # Change {{db-password}}         volumes:           - ./db:/var/lib/mysql         restart: always 
like image 174
Sergiu Avatar answered Sep 18 '22 18:09

Sergiu


In my case, the error caused by lacking a space before service name(like mysql). Hope this information can help someone!

like image 42
KiwenLau Avatar answered Sep 20 '22 18:09

KiwenLau