Talk is cheap

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
➜  ~ sudo systemctl status docker
[sudo] password for codewalker:
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: http://docs.docker.com
➜ ~ sudo systemctl start docker
➜ ~ sudo docker run --name postgre_demo -e POSTGRES_PASSWORD=password1 -d postgres
7e980bd0d15b484feda9076a9e40184bfdc54dee9a1ff64f30792ae586e62259
➜ ~ sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7e980bd0d15b postgres "docker-entrypoint..." 42 seconds ago Up 41 seconds 5432/tcp postgre_demo
➜ ~ sudo docker exec -it postgre_demo psql -U postgres
psql (12.0 (Debian 12.0-2.pgdg100+1))
Type "help" for help.
postgres=# CREATE DATABASE demo_db1;
CREATE DATABASE
postgres=# \c demo_db1;
You are now connected to database "demo_db1" as user "postgres".
demo_db1=# CREATE TABLE demo_t(someting int);
CREATE TABLE
demo_db1=# insert into demo_t(something) values (1);
ERROR: column "something" of relation "demo_t" does not exist
LINE 1: insert into demo_t(something) values (1);
^
demo_db1=# INSERT INTO demo_t (someting) values (1);
INSERT 0 1
demo_db1=# \dt
List of relations
Schema | Name | Type | Owner
--------+--------+-------+----------
public | demo_t | table | postgres
(1 row)
demo_db1=# select someting from demo_t;
someting
----------
1
(1 row)
exit
================================================
sudo docker container stop postgre_demo
postgre_demo
➜ ~ sudo docker container rm postgre_demo
postgre_demo
➜ ~ sudo docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
sudo mkdir /opt/postgresqldb
➜ ~ touch postgresql.demo.sql
➜ ~ cat postgresql.demo.sql
CREATE TABLE demo_t(something int);
INSERT INTO demo_t (something) VALUSE (1);
➜ ~ sudo docker run --name postgres_demo -v /opt/postgresqldb:/opt/demo/ -e POSTGRES_PASSWORD=password1 -d postgres
e4ef75836b9fb13c9aa5a283d449c0156b7fd053ef902d06f2479453f0613264
➜ ~ sudo docker exec -it postgres_demo psql -U postgres -c "CREATE DATABASE demo_db2;"
CREATE DATABASE
➜ ~ sudo docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e4ef75836b9f postgres "docker-entrypoint..." 32 seconds ago Up 30 seconds 5432/tcp postgres_demo
➜ ~ sudo docker exec -it e4e /bin/bash
root@e4ef75836b9f:/# cd /opt/demo/
root@e4ef75836b9f:/opt/demo# ls
postgresql.demo.sql
root@e4ef75836b9f:/opt/demo# cat postgresql.demo.sql
\c demo_db2;
CREATE TABLE demo_t(something int);
INSERT INTO demo_t (something) VALUES (1);
root@e4ef75836b9f:/opt/demo# exit
exit
root@e95aa0b8940a:/opt/demo#
➜ ~ sudo docker exec -it postgres_demo psql -U postgres -f /opt/demo/postgresql.demo.sql
You are now connected to database "demo_db2" as user "postgres".
CREATE TABLE
INSERT 0 1
sudo docker exec -it postgre_demo psql -U postgres
psql (12.0 (Debian 12.0-2.pgdg100+1))
Type "help" for help.
postgres=# select datname from pg_database;
datname
-----------
postgres
demo_db2
template1
template0
(4 rows)
postgres=# \c demo_db2
You are now connected to database "demo_db2" as user "postgres".
demo_db2=# SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';
table_name
------------
demo_t
(1 row)
demo_db2=# \d
List of relations
Schema | Name | Type | Owner
--------+--------+-------+----------
public | demo_t | table | postgres
(1 row)
demo_db2=# SELECT column_name FROM information_schema.columns WHERE table_name ='demo_t';
column_name
-------------
something
(1 row)
demo_db2=# select something from demo_t;
something
-----------
1
(1 row)
demo_db2=# exit
➜ ~ sudo docker container ps
[sudo] password for codewalker:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e4ef75836b9f postgres "docker-entrypoint..." 12 minutes ago Up 12 minutes 5432/tcp postgres_demo
➜ ~ sudo docker container stop e4ef75836b9f
e4ef75836b9f
➜ ~ sudo docker container rm e4e
e4e
➜ ~ sudo docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

EOF
Enjoy
I, simon love this world ❤️