Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker compose file not working: replicas Additional property replicas is not allowed

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

like image 305
Tuhina Singh Avatar asked Apr 23 '17 01:04

Tuhina Singh


2 Answers

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:
like image 97
burnettk Avatar answered Nov 05 '22 00:11

burnettk


This happened to me because I was using docker-compose version 2 but my docker-compose.yml file was for version 1.

My docker-compose.yml file was initially like this:

web:
    image: nginx
    restart: always 

So when I would run docker-compose up , I was getting this error:

(root) Additional property web is not allowed

I downgraded to docker-compose version 1 like this:

docker-compose disable-v2

Now it was working. To get it to work for v2, first I enabled v2:

docker-compose enable-v2

Then I updated my docker-compose.yml like below because docker-compose v2, web can not be the top/outermost value.

services:
  web:
    image: nginx
    restart: always 

I checked the version of docker-compose I was using:

docker-compose --version

I found that I was running version v2.2.3 , before the upgrade it had been 1.29.2.

These days docker-compose comes as part of docker itself. Try below command:

docker compose version
like image 35
Gilbert Avatar answered Nov 04 '22 22:11

Gilbert