I had exact issue with
postgres:9.4, my manifest file looks quite similar:
when I run
docker-compose up I got following errors:
postgres_1 | FATAL: "/var/lib/postgresql/data" is not a valid data directory
postgres_1 | DETAIL: File "/var/lib/postgresql/data/PG_VERSION" does not contain valid data.
postgres_1 | HINT: You might need to initdb.
I confirm that this issue affect version 9.5 and 9.6. The only version that finally get this issue rectified is version
So if you could not afford to use version 10, here is my fix:
and the content of
RUN mkdir -p "$PGDATA" && chmod 700 "$PGDATA"
The gist is to explicitly specifiy
PGDATA and ask docker-compose to use my custom
Dockerfile.postgres file to build the image. The
RUN rule is very self-explanatory, I create a new folder and change mod to
700. And viola, it works