'./docker-compose.yml',服务必须是映射,而不是NoneType

时间:2017-04-17 13:27:49

标签: docker yaml docker-compose

当我跑:COMPOSE_PROJECT_NAME=zk_test docker-compose up时,我收到错误说

  

“错误:在文件'./docker-compose.yml'中,服务必须是映射,而不是   a 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

示例图片:

Sample Image

2 个答案:

答案 0 :(得分:24)

YAML依赖于缩进。此

services:
zoo1:

是一个带有两个键的映射,它们都映射到null(即Python中的None)。

鉴于:

services:
   zoo1:

是嵌套在映射中的映射。关键的服务'具有键zoo1(具有值null)的映射值。

答案 1 :(得分:0)

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

只放一个空格。之前。