我该如何解决我的docker-compose.yml? – 预期<block end>,但find'<block mapping start>'

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 

似乎有我的XML文件中的缩进问题。 我在这里读了一些其他的问题,并尝试了各种缩进scheme。 我仍然无法得到它的工作。 在发布这个问题之前,我有意删除了env名称/密码。

 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 

将来,你可以使用这个网站来检查它有什么问题,然后在旅途中修复它。

编辑:

所以你的docker-compose文件的问题如下:

  1. 你没有添加服务:在版本和

  2. 如果您需要最新的图像,则不必通过:最新的标签,当您需要特定版本的图像时,您将传递标签,并在“


至于代码,应该如下:

 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