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

9.6k views Asked by At

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?

2

There are 2 answers

0
Christopher Caldwell On BEST ANSWER

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
0
Victor Timi On

I had similar issue and Here is how i was able to solve it.

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