PostgreSQL is a powerful, open source object-relational database system with strong reputation for r
100K+
PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance
For development and testing purposes we need pre-setup Postgres server to automate development and auto-testing activity. The container has pre-defined empty database (with flag table to ensure non-production case) and two users.
tcp/5432 - Postgres listening endpoint/data - Hold Postgres'es data/dbseed - Files *.sql from the folder is executing at startup of a container
/dbseed/*.sql - execute in devdb database as postgres user/dbseed/<db_name>/*.sql - execute in <db_name> database as postgres userdevdb"public"."emptytestflag"postgres - superuser (no password)devadmin - owner of the database devdb (no password)devuser - regular user (no password)Start for development
docker run --interactive --tty --rm --publish 5432:5432 theanurin/devel.postgres-13
Use connection strings (no password):
postgres://[email protected]:5432/postgres - to login as superuserpostgres://[email protected]:5432/devdb - to login as devdb ownerpostgres://[email protected]:5432/devdb - to login as regular userIn this scenario your init SQL files are placed in ./init-sql directory and will be applied in alphabetical order.
FROM theanurin/devel.postgres-13 AS postgres_builder
COPY ./init-sql/ /.builder-postgres.d/
RUN /usr/local/bin/docker-builder-postgres-13.sh
FROM theanurin/devel.postgres-13
COPY --from=postgres_builder /build/ /
In this scenario your have to provide shell script /.builder-postgres.sh that will execute at build time. The script responsible for data generation.
#!/bin/sh
#
# sample of generate-data.sh
#
set -e
DB_NAME="my-db"
DB_OWNER="${DB_NAME}-owner"
# Execute command via file using Redirecting Input redirections
psql --dbname=postgres --username=postgres --set user="${DB_OWNER}" --file=<(echo 'CREATE USER :"user" WITH LOGIN;')
# Execute command via Here Documents redirections
psql --dbname=postgres --username=postgres --set db="${DB_NAME}" --set db_owner="${DB_OWNER}" <<-'EOSQL'
CREATE DATABASE :"db" WITH
OWNER = :"db_owner" ENCODING = 'UTF8'
CONNECTION LIMIT = -1;
EOSQL
# Execute command via inline SQL
psql --dbname="${DB_NAME}" --username="${DB_OWNER}" --command='CREATE TABLE "test" ("id" INTEGER NOT NULL);'
echo "Wow, ${DB_NAME} was created successfully!"
FROM theanurin/devel.postgres-13 AS build_stage
COPY ./generate-data.sh /.builder-postgres.sh
RUN chmod +x /.builder-postgres.sh
RUN /usr/local/bin/docker-builder-postgres-13.sh
FROM theanurin/devel.postgres-13
COPY --from=build_stage /build/ /
# Run container
docker run --detach --name pg_builder --publish 5432:5432 theanurin/devel.postgres-13
# Fill you data into Postgres
./my-data-script.sh postgres://[email protected]:5432/postgres
# Stop container and make new image
docker stop pg_builder
docker commit pg_builder my_devel.postgres-13_with_data
# Use image my_devel.postgres-13_with_data
Content type
Image
Digest
sha256:9c466044f…
Size
21 MB
Last updated
almost 2 years ago
docker pull theanurin/devel.postgres-13