Docker container shuts down giving ‘data directory has wrong ownership’ error when executed in windows 10

This is a documented problem with the Postgres Docker image on Windows [1][2][3][4]. Currently, there doesn’t appear to be a way to correctly mount Windows directories as volumes. You could instead use a persistent Docker volume, for example:

  db:
    image: postgres
    environment:
      - POSTGRES_USER=attendize
      - POSTGRES_PASSWORD=attendize
      - POSTGRES_DB=attendize
    ports:
      - "5433:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
    - attendizenet

volumes:
  pgdata:

Other things that didn’t work:

  • Set PGDATA to a subdirectory (See PGDATA Setting)
    environment:
      - PGDATA=/var/lib/postgresql/data/mnt
    volumes:
      - ./pgdata:/var/lib/postgresql/data
  • Use a Bind Mount (docker-compose 3.2)
    volumes:
      - type: bind
        source: ./pgdata
        target: /var/lib/postgresql/data
  • Running as POSTGRES_USER=root

More Information:

GitHub

  • data directory “/var/lib/postgresql/data” has wrong ownership

Docker Forums

  • postgresql-data-pgdata-has-wrong-ownership
  • postgres-to-work-on-persistent-windows-mount

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)