本文介绍了'./docker-compose.yml', service 必须是一个映射,而不是一个 NoneType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行:COMPOSE_PROJECT_NAME=zk_test docker-compose up 时,我收到错误提示

When I ran: COMPOSE_PROJECT_NAME=zk_test docker-compose up, I got error saying

"错误:在文件 './docker-compose.yml' 中,服务必须是一个映射,而不是一个 NoneType.".

这是我的 yml 文件:

This is my yml file:

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

示例图片:

推荐答案

YAML 依赖于缩进.这个

YAML is indentation dependent. This

services:
zoo1:

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

is a mapping with two keys that both map to null (i.e. None in Python).

鉴于:

services:
   zoo1:

是嵌套在映射中的映射.键services"的值是一个与键 zoo1 的映射(它的值又是 null).

is a mapping nested in a mapping. The key 'services' has as value a mapping with key zoo1 (which again has a value null).

这篇关于'./docker-compose.yml', service 必须是一个映射,而不是一个 NoneType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 19:18