docker compose file not working: replicas Addition

2019-04-18 12:22发布

问题:

docker version: 17.03.1-ce

Trying to get the docker-compose.yml working from the getting started tutorials.

version: "3"
   services:
     web:
       image: tuhina/friendlyhello:2.0
     deploy:
       replicas: 5
       resources:
         limits:
           cpus: "0.1"
           memory: 50M
      restart_policy:
        condition: on-failure
      ports:
        - "80:80"
      networks:
        - webnet
    networks:
      webnet:

Getting this error:

replicas Additional property replicas is not allowed

What have I typed in wrong?

Thanks.

edit: docker-compose version 1.11.2, build dfed245

回答1:

Indentation is critical in docker-compose.yml. The way you have it set up, "deploy" is a service, which is not intended. The deploy section is intended to specify information about how the "web" service should be deployed. The following allows docker-compose up and docker stack deploy web --compose-file docker-compose.yml to run successfully for me:

version: "3"

services:
  web:
    image: tuhina/friendlyhello:2.0
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: '50M'
      restart_policy:
        condition: on-failure
    ports:
      - "80:80"
    networks:
      - webnet

networks:
  webnet: