Docker compose Docker Compose中存在无效类型错误

Docker compose Docker Compose中存在无效类型错误,docker-compose,Docker Compose,我在Docker写作中面临错误。撰写文件是 version: '2' services: api: build: context: . dockerfile: webapi/dockerfile ports: - 210 web: build: context: . dockerfile: app/dockerfile ports: - 80 lbapi: image:

我在Docker写作中面临错误。撰写文件是

version: '2'

services:
  api:
    build:
      context: .
      dockerfile: webapi/dockerfile
    ports:
       - 210
  web:
    build:
      context: .
      dockerfile: app/dockerfile
    ports:
      - 80
  lbapi:
    image: dockercloud/haproxy
    links:
       – api
    ports:
       – 8080:210
  lbweb:
    image: dockercloud/haproxy
    links:
       – web
    ports:
       – 80:80
运行
docker compose up
时的错误是:

ERROR: The Compose file '.\docker-compose.yml' is invalid because:
services.lbapi.ports contains an invalid type, it should be an array
services.lbweb.ports contains an invalid type, it should be an array
services.lbapi.links contains an invalid type, it should be an array
services.lbweb.links contains an invalid type, it should be an array
请帮忙

  • docker compose版本1.8.0-rc1,构建9bf6bc6
  • docker py版本:1.8.1
  • CPython版本:2.7.11
  • OpenSSL版本:OpenSSL 1.0.2d 2015年7月9日
您是否尝试过:

version: '2'

services:
  api:
    build:
      context: .
      dockerfile: webapi/dockerfile
    ports:
       - 210
  web:
    build:
      context: .
      dockerfile: app/dockerfile
    ports:
      - 80
  lbapi:
    image: dockercloud/haproxy
    links:
       – api
    ports:
       – "8080:210"
  lbweb:
    image: dockercloud/haproxy
    links:
       – web
    ports:
       – "80:80"

您应该用引号(“8080:210”)包围端口,因为docker在“ports”数组中需要字符串或数字,但8080:210实际上不是这两个字符串或数字。请参见

,查看此页面上的任何人-因为它目前是google上的顶级搜索结果-请检查您的语法。这主要是因为缺少缩进、双引号、缺少空格等


有关正确语法示例的参考,请查看docker的文档:

docker compose希望端口采用数组格式,您需要使用大括号覆盖某些参数。 例如:

...
ports: ["8080:8080"]
...

此外,确保从web或其他来源复制时,正确设置引号的格式并加以应用。

此外,如果从web复制,请确保所有引号都是简单的ASCII
而不是打开/关闭样式,还要检查
-
是否是一个简单的减号,而不是unicode em或en破折号。如果能看到您在配置中具体更改了什么,那就太好了。他在端口上添加了引号。”