Skip to content

Instantly share code, notes, and snippets.

@andy108369
Last active September 11, 2022 18:26
Show Gist options
  • Save andy108369/7718b0c3d0c658ccf2e6ca27f5eb6946 to your computer and use it in GitHub Desktop.
Save andy108369/7718b0c3d0c658ccf2e6ca27f5eb6946 to your computer and use it in GitHub Desktop.

Final work is here and a working SDL manifest

What's below on this page is outdated:


asciicast

  1. Init the DB with postgres:adminpass creds
docker network create pgnet1
docker volume create pgvol1
docker run -d --name db1 --hostname db1 --network pgnet1 -e POSTGRES_PASSWORD=adminpass -v pgvol1:/var/lib/postgresql/data postgres:14
  1. Create a new DB "newdb", with newdb_user:userpass creds
docker run --rm -ti --network pgnet1 -e PGPASSWORD=adminpass -e PGUSER=postgres -e PGHOST=db1 -u postgres --entrypoint psql postgres:14

CREATE USER newdb_user;
CREATE DATABASE newdb;
GRANT ALL PRIVILEGES ON DATABASE newdb TO newdb_user;
ALTER USER newdb_user WITH PASSWORD 'userpass';

\l+
\q
  1. Connect to the "newdb" with "newdb_user" and create a table called "company"
docker run --rm -ti --network pgnet1 -e PGPASSWORD=userpass -e PGUSER=newdb_user -e PGDATABASE=newdb -e PGHOST=db1 -u postgres --entrypoint psql postgres:14

CREATE TABLE COMPANY(
   ID INT PRIMARY KEY     NOT NULL,
   NAME           TEXT    NOT NULL,
   AGE            INT     NOT NULL,
   ADDRESS        CHAR(50),
   SALARY         REAL
);

\dt+
\q
  1. Restart the db1
docker logs db1
docker restart db1
docker logs db1
  1. Check the connection and the table again
docker run --rm -ti --network pgnet1 -e PGPASSWORD=userpass -e PGUSER=newdb_user -e PGDATABASE=newdb -e PGHOST=db1 -u postgres --entrypoint psql postgres:14

\dt+
\q
  1. Tear everything down
docker rm -f db1
docker volume rm pgvol1
docker network rm pgnet1
@andy108369
Copy link
Author

andy108369 commented Sep 11, 2022

Final work is here and a working SDL manifest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment