Skip to content

Instantly share code, notes, and snippets.

@hoangquochung1110
Created May 19, 2023 10:49
Show Gist options
  • Save hoangquochung1110/5486440c7e2b43f98135ff7803750b5f to your computer and use it in GitHub Desktop.
Save hoangquochung1110/5486440c7e2b43f98135ff7803750b5f to your computer and use it in GitHub Desktop.
Example docker compose setup for postgres with db initialization scripts (https://github.com/docker-library/docs/tree/master/postgres#initialization-scripts)
version: "3"
services:
db:
image: postgres:14
container_name: my-postgres-14
ports:
- "5432:5432"
environment:
POSTGRES_USER: hunghoang
POSTGRES_PASSWORD: manager
POSTGRES_DB: postgres-internals-14
volumes:
- db_data:/var/lib/postgresql/
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
volumes:
db_data:
CREATE TABLE accounts(
id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
client text,
amount numeric
);
INSERT INTO accounts VALUES (1, 'alice', 1000.00), (2, 'bob', 100.00), (3, 'bob', 900.00);
CREATE ROLE readonly LOGIN PASSWORD 'readonly';
GRANT SELECT ON accounts TO readonly;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment