问题描述
我尝试了解容器,但我的 docker-compose.yml 文件有问题,在我运行 docker compose up 后,我总是遇到相同的错误:
I try to learn about container, but i have a problem with my docker-compose.yml file, after i run the docker compose up, i always get the same error:
"错误:yaml.scanner.ScannerError:不允许映射值这里"
即使我将挂载路径更改为 docker 卷,我也遇到了同样的错误,这是我的 yml
文件
even if i changed the mount path to docker volume, i got the same error, this is my yml
file
version: "3"
services:
database:
image: mariadb
ports:
- "3260:3260"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/mariadb:var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
wordpress:
image: wordpress
ports:
- "2000:80"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/wordpress:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: root
depends_on:
- database
links:
- database
推荐答案
您的 yaml 似乎无效.当我遇到这些类型的问题时,我会做的是使用一个名为 http://www.yamllint.com/ 将为您验证语法.
It appears that your yaml is invalid. When I face these types of issues, what I will do is use a site called http://www.yamllint.com/ which will validate the syntax for you.
这个基于你的例子的 yaml 是有效的:
This yaml based on your example is valid:
注意:您可以使用 4 个空格(或我更喜欢的 2 个),但切勿使用制表符.
version: "3"
services:
database:
environment:
MYSQL_ROOT_PASSWORD: root
image: mariadb
ports:
- "3260:3260"
volumes:
- "/home/randy/Desktop/Latihan/wordpress-mariadb/mariadb:var/lib/mysql"
wordpress:
image: wordpress
ports:
- "2000:80"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/wordpress:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: root
depends_on:
- database
links:
- database
这篇关于这里不允许 yml docker-compose 错误映射值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!