Docker Community Forums

Share and learn in the Docker community.

The postgres container cannot start in docker


I am new to the docker. I tried to start the postgres container in docker but kept receiving below error message:

PostgreSQL Database directory appears to contain a database; Skipping initialization

FATAL: could not open directory "pg_tblspc": No such file or directory

LOG: database system is shut down

The postgres part in my docker-compose.yml is as below:

    image: postgres:9.6
        - POSTGRES_USER=airflow
        - POSTGRES_PASSWORD=airflow
        - POSTGRES_DB=airflow
    # Uncomment these lines to persist data on the local filesystem.
        - PGDATA=/var/lib/postgresql/data/pgdata
        - ./pgdata:/var/lib/postgresql/data/pgdata

I searched /var/lib on my machine and there is no postgresql folder existing. No sure if it was to do with the user permission.

Any suggestions would be appreciated.

You don’t tell us what system you use, so it’s not quit easy to help you.
Try to replace the mounted folder from your host with a named volume ‘pgdata’ and mount it into ...postgresql/data, not ...postgresql/data/pgdata:

      - pgdata:/var/lib/postgresql/data


You’ll see the warning ‘PostgreSQL Database directory appears to contain a database; Skipping initialization’ on every subsequent start, this is nothing to worry about, but the ‘could not open…’ error probably indicates that the permissions of your mounted folder are incorrect.

This folder only exists in the container, not on your host.