23

This is my sample docker-compose.yml file.

version: '2'
config-server:
  image: ccc/config-server
  restart: always
registration-server:
  image: ccc/registration-server
  restart: always
  ports:
    - 1111:1111

When I use docker-compose up -d I get an error:

"ERROR: The Compose file './docker-compose.yml' is invalid because:
Additional properties are not allowed ('registration-server', 'config-server' were unexpected)

You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

4 Answers 4

42

You are missing a services keyword, your correct .yml is:

version: '2'
services:
  config-server:
    image: ccc/config-server
    restart: always
  registration-server:
    image: ccc/registration-server
    restart: always
    ports:
      - 1111:1111
1
6

This can also happpen if one of the keys is misspelled. In my case memory was spelled incorrectly:

After fixing it:

version: "3.8"
services:
  redis:
    image: redis:alpine
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 50M
        reservations:
          cpus: '0.25'
          memory: 20M
3

In the This can also happen if, this can also happens if global level volumes is indented wrong, like not starting at column 0.

1
0

use this for your docker-compose.yml

services:
  postgres:
    image: postgres:15-alpine
    ports:
      - 5432:5432
    environment: 
      POSTGRES_DB: webapp_dev
      POSTGRES_HOST_AUTH_METHOD: trust 

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.