docker-compose:服务不支持的配置选项:'web'

docker-compose : Unsupported config option for services service: 'web'

我正在浏览 Getting Started with Docker Compose 页面。

在第 3 步中,我制作了一个 docker-compose.yml 文件,如下所述:

version: '2'
services:
    web:
        build: .
        ports: 
            - "5000:5000"
        volumes: 
            - .:/code
        depends_on:
            - redis
    redis:
        image: redis

但是当我运行:

$ docker-compose up

我收到以下错误:

Unsupported config option for services service: 'web'

我做错了什么?我无法弄清楚发生了什么。

在今年 2 月左右发布的 docker-compose version 1.6 中引入了对第 2 版 compose 文件格式的支持。

您使用的是 2015 年 7 月的 1.3.3。

您需要升级到更新的版本才能使用版本 2 格式的配置文件。

由于这是谷歌搜索的第一个结果“docker-compose 不支持的服务配置选项”,我想补充一点,截至 2020 年最常见的原因是缺少 version: "3"

只需将 version: "3" 添加到 docker-compose.yml 的开头即可。

来自docs

There are currently three versions of the Compose file format:

  1. Version 1, the legacy format. This is specified by omitting a version key at the root of the YAML.
  2. Version 2.x. This is specified with a version: '2' or version: '2.1', etc., entry at the root of the YAML.
  3. Version 3.x, the latest and recommended version, designed to be cross-compatible between Compose and the Docker Engine’s swarm mode. This is specified with a version: '3' or version: '3.1', etc., entry at the root of the YAML.

就我而言,我使用了错误的缩进。重新检查 docker-compose 文件的缩进以确保其正确