在文件'./docker-compose.yml'中,服务'image'必须是映射而不是字符串

时间:2019-11-28 09:54:11

标签: docker docker-compose yaml

我想创建一个 .yml文件,我可以执行该文件以将wordpress与mysql一起使用。我是关于docker composoe的docker的新手,所以我的代码是:

web:
    image: wordpress
    links:
     - mysql
    environment:
     - WORDPRESS_DB_PASSWORD=sample
    ports:
     - "127.0.0.3:8080:80"
mysql:
image: mysql:latest
environment:
 - MYSQL_ROOT_PASSWORD=sample
 - MYSQL_DATABASE=wordpress

我做docker-compose up并收到此错误:

ERROR: In file './docker-compose.yml', service 'image' must be a mapping not a string.

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:3)

这是Yaml格式错误。 您应该这样格式化

web:
    image: wordpress
    links:
     - mysql
    environment:
     - WORDPRESS_DB_PASSWORD=sample
    ports:
     - "127.0.0.3:8080:80"
mysql:
    image: mysql:latest
    environment:
     - MYSQL_ROOT_PASSWORD=sample
     - MYSQL_DATABASE=wordpress

答案 1 :(得分:1)

mysql:附近的缩进是错误的,请按以下说明更正缩进

web:
image: wordpress
links:
 - mysql
environment:
 - WORDPRESS_DB_PASSWORD=sample
ports:
 - "127.0.0.3:8080:80"
mysql:
    image: mysql:latest
    environment:
    - MYSQL_ROOT_PASSWORD=sample
    - MYSQL_DATABASE=wordpress

您可以在https://onlineyamltools.com/validate-yaml上验证yml