错误:“./docker-compose.yml”中的版本不受支持。 您可能会看到此错误,因为您使用了错误的撰写文件版本

这是docker-compose.yml

version: “2” services: web: build: . environment: MONGO_URI="mongodb://ravimongo:27017" ports: — “3000:3000” links: — ravimongo depends_on: — ravimongo ravimongo: image: mongo:3.2.6 ports: — “27017:27017” 

这是错误:

 ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version ("2.0", "2.1", "3.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/ 

版本详细信息如下:docker-compose版本

 docker-compose version 1.11.2, build dfed245 docker-py version: 2.1.0 CPython version: 2.7.12 OpenSSL version: OpenSSL 1.0.2j 26 Sep 2016 

docker版本

 Client: Version: 17.03.1-ce API version: 1.27 Go version: go1.7.5 Git commit: c6d412e Built: Tue Mar 28 00:40:02 2017 OS/Arch: darwin/amd64 Server: Version: 17.03.1-ce API version: 1.27 (minimum version 1.12) Go version: go1.7.5 Git commit: c6d412e Built: Fri Mar 24 00:00:50 2017 OS/Arch: linux/amd64 Experimental: true 

我在http://www.yamllint.com/和https://codebeautify.org/yaml-validator中validation了yaml语法。 我无法find问题。

YAML是有效的。 但是,您正在使用左侧双引号如此:

version: “2”

基于这个错误,好像Docker Compose不能正确parsing版本。 如果您使用左侧双引号而不是引号 ,那么由Docker构build的版本将是“2”而不是2 ,因此它将不能等同于支持的版本( "2.0""2.1""3.0" )。 我build议将其更改为以下内容:

version: "2"

让我知道,如果错误仍然存​​在。

如错误日志中所述,您应该将其replace为“2.0”而不是简单的“2”。

你的编辑器注入的是智能引号,而不是正常的ASCII引号:

 version: “2” 

这需要是:

 version: "2" 

我build议不要使用该编辑器编写yml文件,以避免将来出现问题。