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
我的yml文件中似乎存在缩进问题。我在这里阅读了其他一些问题,并尝试了各种缩进方案。我仍然无法让它发挥作用。在发布此问题之前,我故意删除了env名称/ pws。
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
答案 0 :(得分:12)
将来,您可以使用此website来检查它有什么问题,然后随时修复。
修改强>
所以你的docker-compose文件遇到的问题如下:
您没有在版本之后添加服务:并且
如果您想要最新的图像,则不必传递:latest 标记,当您需要特定版本的图像时,您将传递标记,并且在“ “
至于代码,它应该如下:
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
答案 1 :(得分:5)
在我的情况下,由服务名称之前缺少空格(如mysql)引起的错误。希望这些信息可以帮助别人!
答案 2 :(得分:-1)
对我来说,问题在于线的缩进不足。 我在出现问题的行中添加了一个标签,并在此标签的进一步依赖旁边添加了标签。