It seems to me that Postgres is ignoring my envar and the sql script
Here’s my docker-compose
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: mysecretpassword
PGDATA: /var/lib/postgresql/data/pgdata
POSTGRES_DB: ecommerce
volumes:
- /custom/mount:/var/lib/postgresql/data
- ./sql_script.sql:/docker-entrypoint-initdb.d/sql_script.sql
ports:
- 5432:5432
adminer:
image: adminer
restart: always
ports:
- 8080:8080
In the doc is saying that I can change the default database name using POSTGRES_DB env var but is not working for me. At first my intention was to create the database using a sql_script.sql through volumes, got it from the doc as well but didn’t work.
Thanks in advance.
2
Answers
The
POSTGRES_DB
variable is only used if your/custom/mount
directory is empty. If it already contains a database, the variable isn’t used.From the docs:
Delete the contents of the directory and run your container again, and it should create the database.
If you want to use the POSTGRES_DB variable to create a new database even if the
/custom/mount
directory already contains a database, you can modify the startup process of the PostgreSQL container. PGSQL Docker Documentation