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

3
  • What version of compose are you using? Apr 23, 2017 at 1:23
  • @RobertMoskal : Thanks! - edited the question to add docker-compose version Apr 23, 2017 at 1:25
  • 1
    This error also can be caused if you specify old version like I did "3.6". You must bump it to "3.8". Aug 8, 2021 at 7:40

4 Answers 4

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:
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
3
  • 2
    Thank you, I've referenced this answer many times Mar 21, 2022 at 13:45
  • on macos, I get "host" network_mode is incompatible with port_bindings after doing docker-compose disable-v2, it work well on linux but not mac Dec 27, 2022 at 16:02
  • Can you do: docker compose version . Ideally you shouldn't disable V2, it's only for demonstrative purposes.
    – Gilbert
    Dec 28, 2022 at 17:12
7

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

I used enviroment instead of environment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.