Docker 撰写文件无效,不允许附加属性
Docker Compose file is invalid, additional properties not allowed
这是我的示例 docker-compose.yml 文件。
version: '2'
config-server:
image: ccc/config-server
restart: always
registration-server:
image: ccc/registration-server
restart: always
ports:
- 1111:1111
当我使用 docker-compose up -d
时出现错误:
"ERROR: The Compose file './docker-compose.yml' is invalid because:
Additional properties are not allowed ('registration-server', 'config-server' were unexpected)
You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
您缺少 services
关键字,正确的 .yml 是:
version: '2'
services:
config-server:
image: ccc/config-server
restart: always
registration-server:
image: ccc/registration-server
restart: always
ports:
- 1111:1111
如果其中一个键拼写错误,也会发生这种情况。在我的例子中,内存拼写错误:
修复后:
version: "3.8"
services:
redis:
image: redis:alpine
deploy:
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M
在中,如果也会发生这种情况,如果全局级别 volumes
缩进错误,例如不从第 0 列开始,也会发生这种情况。
这是我的示例 docker-compose.yml 文件。
version: '2'
config-server:
image: ccc/config-server
restart: always
registration-server:
image: ccc/registration-server
restart: always
ports:
- 1111:1111
当我使用 docker-compose up -d
时出现错误:
"ERROR: The Compose file './docker-compose.yml' is invalid because:
Additional properties are not allowed ('registration-server', 'config-server' were unexpected)
You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
您缺少 services
关键字,正确的 .yml 是:
version: '2'
services:
config-server:
image: ccc/config-server
restart: always
registration-server:
image: ccc/registration-server
restart: always
ports:
- 1111:1111
如果其中一个键拼写错误,也会发生这种情况。在我的例子中,内存拼写错误:
修复后:
version: "3.8"
services:
redis:
image: redis:alpine
deploy:
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M
在中,如果也会发生这种情况,如果全局级别 volumes
缩进错误,例如不从第 0 列开始,也会发生这种情况。