问题
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