Created
May 19, 2023 10:49
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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