This is a simple example where we create a Postgres Docker container and connect to it using pgAdmin. We will also run migrations at container boot.


Setup


version: "3.4"

services:
shop-postgres:
container_name: "shop-postgres"
image: "postgres:13.2-alpine"
ports:
- "5432:5432"
environment:
POSTGRES_DB: "shop"
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"
volumes:
- "./init.sql:/docker-entrypoint-initdb.d/init.sql"

# init.sql

CREATE SEQUENCE IF NOT EXISTS payments_id_seq;

CREATE TABLE IF NOT EXISTS payments
(
id INTEGER NOT NULL DEFAULT nextval('payments_id_seq'),
uuid CHARACTER VARYING(36) NOT NULL,
card_number CHARACTER VARYING(16) NOT NULL,
card_cvv SMALLINT NOT NULL,
currency CHARACTER VARYING(3) NOT NULL,
...
CONSTRAINT payments_pk_id PRIMARY KEY (id),
CONSTRAINT payments_uq_uuid UNIQUE (uuid)
);

# pgAdmin connection

host: localhost
port: 5432
user: postgres
pass: postgres