36

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

5 Answers 5

23

Did you try with quotes on ports?

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"
1
  • 5
    He added quote on ports
    – Toothgip
    Commented Apr 9, 2021 at 14:27
20

For anyone ending up on this page - as it for now is the top search result on google - please check your syntax. It's mostly because of missing indent, double quotation marks, missing space, etc.

For reference in regards to an example of correct syntax, check the documentation from docker: https://docs.docker.com/compose/compose-file/

2
  • 1
    Also, if you copied from the web make sure that all the quotation marks are simple ASCII " and not an open/close style and also check that - is a simple minus sign and not a unicode em or en dash.
    – Ian Mercer
    Commented Sep 20, 2020 at 7:05
  • 1
    much more useful than the top answer, thanks! Commented Jan 21, 2022 at 23:30
6

You should surround ports with quotation marks("8080:210") because docker-compose expecting string or number in "ports" array but 8080:210 is not really either of them. See https://docs.docker.com/compose/compose-file/#ports

5

The docker compose expects the ports to be in the array format, for which you need to cover certain parameters with braces. For example:

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

Also, make sure that when copying from web or other sources, format the quotes properly and apply it.

1
  • It's strange, everywhere I've seen tutorials, ports were only in quotation marks, but this didn't work for me. But THIS did >> ports: ["8080:8080"] THANK YOU!!! Commented May 1, 2022 at 15:52
1

in my case I was not giving space after dash Previous(with error)- zookeeper: image: wurstmeister/zookeeper container_name: zookeeper ports: -"2181:2181" Working- zookeeper: image: wurstmeister/zookeeper container_name: zookeeper ports: - "2181:2181"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.