What to do if you get the following error when trying to create PostgreSQL with docker-compose
Former story https://stackoverflow.com/questions/51168558/how-to-mount-a-postgresql-volume-using-aws-ebs-in-kubernete
postgres-db | initdb: error: directory "/var/lib/postgresql/data" exists but is not empty
postgres-db | It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.
postgres-db | Using a mount point directly as the data directory is not recommended.
postgres-db | Create a subdirectory under the mount point.
postgres-db exited with code 1
Attempting to create data in / var / lib / postgresql / data
has failed.
The solution is to specify the environment variable PGDATA
to specify the location of the database body, which is changed from the default / var / lib / postgresql / data
to / var / lib / postgresql / data / pgdata
. There is a possibility that it can be solved by deepening one layer like (pgdata can be another name).
In the following example, volumes / postgres_root
mounts the container / var / lib / postgresql / data
, environment / PGDATA
, and / var / lib / postgresql / data / pgdata
. Create data in the location. ..
20-10-23 fix
volumes: postgres_root: driver_opts: type: none doesn't seem to work on Mac and windows, so fix it
version: '3'
services:
postgres:
image: postgres:12.2
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 'pass'
POSTGRES_DB: 'pg'
PGDATA: /var/lib/postgresql/data/pgdata
ports:
- 5432:5432
container_name: postgres-db
volumes:
- ./db/postgres:/var/lib/postgresql/data
- ./db/logs:/var/log
Recommended Posts