Docker-Compose postgres upgrade initdb: error: directory “/var/lib/postgresql/data” exists but is not empty

Quoting @yosifkit from this issue

The volume needs to be empty or a valid already initialized postgres
database with the file PG_VERSION in there so the init can be
skipped.

… If there are any files or folders in there like lost+found it
will probably fail to initialize. If there are files that you want to
keep in the volume (or have no control over) you could adjust the
PGDATA environment variable to point to a sub-directory in there
like -e PGDATA=/var/lib/postgresql/data/db-files/.

So I added PGDATA to the environment section of the compose file to solve the issue (notice the some_name at the end):

services:
  postgres:
    image: postgres:12
    environment:
      PGDATA: /var/lib/postgresql/data/some_name/

Leave a Comment

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