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

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

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

Tags:

Docker

Yaml