This is a postgres image that builds on top of the official postgres image.
The only difference with the official image is the addition of an initialization script that allows you to create multiple databases by passing an additional environment variable.
By default, we normally use the POSTGRES_DB env variable to set the name of the database.
Using this image you can provide an additional environment variable POSTGRES_MULTIPLE_DATABASES to create additional databases. POSTGRES_MULTIPLE_DATABASES accepts a comma-separated value of the name of the database
Example:
services:
db:
image: mplibunao/postgres:13.2
ports:
- "5432:5432"
environment:
- POSTGRES_USER: postgres
- POSTGRES_PASSWORD: postgres
- POSTGRES_DB: api
- POSTGRES_MULTIPLE_DATABASES: api_dev,api_test
Running docker-compose up using the docker-compose.yml above will create an api, api_dev and api_test database. However api_dev and api_test will use different users. See #postgres_multiple_databases
Note: Similar to the original postgres image, the initialization script only runs when you start the container with an empty data directory
Please see the original image's documentation for more info hub docker _ postgres
POSTGRES_MULTIPLE_DATABASESTo create multiple databases, pass a comma-separated string with the name of the databases to the env variable POSTGRES_MULTIPLE_DATABASES
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_MULTIPLE_DATABASES: dev,test
Aside from creating the databases, a user with the same name as the database name will be created for each database. This follows the principle of least privilege to improve security and isolation between databases or environments by not using the postgres user for for all databases
In the example above, a user dev will be created along with the dev database
psql -h localhost -p 5432 -U dev
POSTGRES_USERThis is the same env variable from the official postgres image for creating the specified user with superuser power. Used in conjunction with POSTGRES_PASSWORD
POSTGRES_PASSWORDThis is the same env variable from the official postgres image for setting the password for the superuser.
This is also used as the password for users created using POSTGRES_MULTIPLE_DATABASES
export PGPASSWORD=postgres
psql -h localhost -p 5432 -U dev
You can see the repo at github mplibunao docker containers tree master postgres and build the image yourself
docker-compose up to build and run the containerdocker-compose.ymldocker-compose buildContent type
Image
Digest
sha256:8934713b5…
Size
145.8 MB
Last updated
almost 3 years ago
docker pull mplibunao/postgres