Mayank
Mayank

Reputation: 1631

Invalid type error in Docker Compose

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.

Upvotes: 36

Views: 128593

Answers (5)

akhil Raj Kunwar
akhil Raj Kunwar

Reputation: 92

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"

Upvotes: 1

Nguyen Sy Thanh Son
Nguyen Sy Thanh Son

Reputation: 5376

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"

Upvotes: 23

G07cha
G07cha

Reputation: 4154

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

Upvotes: 6

S V Naresh
S V Naresh

Reputation: 89

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.

Upvotes: 5

nelion
nelion

Reputation: 1962

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/

Upvotes: 20

Related Questions