19

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/
halfer
  • 19,824
  • 17
  • 99
  • 186
Chintamani
  • 1,076
  • 7
  • 23
  • 47

4 Answers4

35

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
michael_bitard
  • 3,613
  • 1
  • 24
  • 35
5

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
z atef
  • 7,138
  • 3
  • 55
  • 50
1

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

Fabien Haddadi
  • 1,814
  • 17
  • 22
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