Docker撰写错误“在文件'./docker-compose.yml'中,服务'punjab'必须是映射而不是字符串。” [英] Docker compose error "In file './docker-compose.yml', service 'punjab' must be a mapping not a string."
问题描述
我在docker-compose.yml文件中遇到一个奇怪的错误。
I am getting a strange error in my docker-compose.yml file.
我已经为堆栈旁遮普连接管理器ejabberd和mysql。
I have prepared a docker-compose file for the stack punjab connection manager, ejabberd and mysql.
下面是docker-compose.yml文件
Below is the docker-compose.yml file
version: '2'
services:
punjab:
image:punjab
ports
- 5280:5280
links
- ejabbberd:ejabberd
ejabberd:
image: ejabberd
depends-on:
- mysql
links:
- mysql:mysql
mysql:
image:mysql
当我从命令行运行docker-compose命令时我有docker-compose.yml文件的目录,出现以下错误。
When I run the command docker-compose up from the command line and from the same directory where I have the docker-compose.yml file, I get the following error.
错误:在文件'./docker-compose.yml'中,服务'punjab'必须是映射而不是字符串。
我也使用yamllint解析了yml文件,并且文件格式正确。
I parsed the yml file using yamllint as well and the file is correctly formatted.
推荐答案
尽管从理论上讲文件格式看起来正确,但是有些错误。
Although in theory the file format may look correct, there are some things that are wrong.
它们是:
-
使用
depends_on
代替depends -on
,因为这是正确的语法。
Use
depends_on
instead ofdepends-on
because that is the correct syntax.
为获得最佳实践,请在通知图像之前使用空格,例如:图片:旁遮普
。
For best practice, use a blank space before informing the image like: image: punjab
.
在端口
和链接
在旁遮普语服务中,您忘记了冒号:
On ports
and links
at punjab service, you forget the colon :
图像 ejabberd
和 punjab
在Docker Hub上不存在,因此它们必须存在于本地存储库中。 / p>
The images ejabberd
and punjab
do not exist on Docker Hub so they must exist in your local repository.
这是使用 docker-compose.yml
:
version: '2'
services:
punjab:
image: punjab
ports:
- "5280:5280"
links:
- ejabberd
ejabberd:
image: ejabberd
depends_on:
- mysql
links:
- mysql
mysql:
image: mysql
这篇关于Docker撰写错误“在文件'./docker-compose.yml'中,服务'punjab'必须是映射而不是字符串。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!