Invalid type error in Docker Compose

橙三吉。 提交于 2019-12-23 07:37:30

问题


I am facing error in Docker Compose. The compose file is

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

The error when running docker-compose up is:

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

Please help.

  • docker-compose version 1.8.0-rc1, build 9bf6bc6
  • docker-py version: 1.8.1
  • CPython version: 2.7.11
  • OpenSSL version: OpenSSL 1.0.2d 9 Jul 2015

回答1:


Did you try:

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"



回答2:


You should cover ports with brackets because docker-compose expecting string or number in "ports" array but 8080:210 is not a number. See https://docs.docker.com/compose/compose-file/#ports



来源:https://stackoverflow.com/questions/37960226/invalid-type-error-in-docker-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!