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
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.
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.
The default path for a Compose file is ./docker-compose.yml .
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:
You didn't add services: after the version and
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
In my case, the error caused by lacking a space before service name(like mysql). Hope this information can help someone!
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