“./docker-compose. yml”,服务必须是Map,而不是NoneType

z9smfwbn  于 2023-06-29  发布在  Docker
关注(0)|答案(3)|浏览(172)

当我运行:COMPOSE_PROJECT_NAME=zk_test docker-compose up时,我得到错误提示
错误:在文件“./docker-compose. yml”中,服务必须是Map,而不是NoneType。
这是我的YML文件:

version: '2'
services:
zoo1:
image: zookeeper
restart: always
container_name: zoo1
ports:
- "2181:2181"
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888

zoo2:
image: zookeeper
restart: always
container_name: zoo2
ports:
- "2182:2181"
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888

zoo3:
image: zookeeper
restart: always
container_name: zoo3
ports:
- "2183:2181"
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888

示例图像:

cedebl8k

cedebl8k1#

YAML依赖于缩进。这

services:
zoo1:

是具有两个键的Map,这两个键都Map到null(即Python中的None)。
鉴于:

services:
   zoo1:

是嵌套在Map中的Map。关键字“services”具有与关键字zoo1的Map作为值(其再次具有值null)。

r1zhe5dt

r1zhe5dt2#

version: '2'                                                                    
services:                                                                          
  autodiscovery:                                                                   
  build: ./autodiscovery/                                                          
  mem_limit: 128m                                                                  
  expose:                                                                          
    - 53                                                                           
    - 8300                                                                         
    - 8301                                                                         
    - 8302                                                                         
    - 8400                                                                         
    - 8500                                                                         
  ports:                                                                           
    - 8500:8500                                                                    
  dns:                                                                             
    - 127.0.0.1

只放一个空格。之前

mwecs4sa

mwecs4sa3#

要解决错误消息,只需将“ports:”语句放在“services:”代码块下,1或2个制表符空间就足够了。

相关问题