dockerdocker-composedocker-cli

Docker CLI failing to compose with "Additional property postgres is not allowed"


My docker-compose.yml looks like this

postgres:
    container_name: postgres-container-1
    image: postgres:latest
    ports:
        - "15432:5432"

When I try to run

docker compose up -d

I get following error

(root) Additional property postgres is not allowed

However when I run

 docker-compose up -d

everything runs as intended, but I get info message that

Docker Compose is now in the Docker CLI, try `docker compose up`

So I assume that docker-compose will soon be obsolete... What did I do wrong?


Solution

  • I had this issue as well. This other StackOverflow post fixed it for me.

    I needed the services: key at the top, with postgres: nested under it.

    My docker-compose.yml

    services:
      postgres:
        image: postgres:latest
        environment:
          POSTGRES_PASSWORD: password1
          POSTGRES_USER: postgres
          POSTGRES_DB: some-db
        ports:
          - '5432:5432'
        volumes:
          - ./sql/setup.sql:/docker-entrypoint-initdb.d/init.sql