Bu, bir Postgres Docker konteyner oluşturduğumuz ve pgAdmin kullanarak ona bağlandığımız basit bir örnektir. Ayrıca konteyner başlangıcında yapılarıda çalıştıracağız.


Kurulum


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"
command: >
postgres -c log_statement=all -c log_destination=stderr

# 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