48

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

Tuhina Singh
  • 927
  • 2
  • 10
  • 19

4 Answers4

77

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:
Matt
  • 68,711
  • 7
  • 155
  • 158
burnettk
  • 13,557
  • 4
  • 51
  • 52
28

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
Gilbert
  • 2,699
  • 28
  • 29
7

For people stumbling upon this question; double check the property name.

I used enviroment instead of environment

Maarten
  • 402
  • 5
  • 20
0

Second most voted suggestion worked for me.

Check your version of docker-compose - docker compose version

If it is version 2 or above then docker-compose written in basic format will not work if you use docker compose up command.

So make sure to disable the version 2 or above to test docker-compose.yml file of older versions with command: docker-compose disable-v2

Now test with docker compose up command & observe compose will work. Check image below for more info.

enter image description here

Note: Do not forget to enable the latest version with command: docker-compose enable-v2