-
Notifications
You must be signed in to change notification settings - Fork 0
/
pg_in_docker.sh
51 lines (45 loc) · 1.47 KB
/
pg_in_docker.sh
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
#!/usr/bin/env bash
# run a basic local postgres container
sudo docker run \
--rm \
--name pg \
-e POSTGRES_PASSWORD=postgres \
-p 5432:5432 \
-d postgres:10
# run a postgres container for remote connections
# now you can hit the postges port remotely by binding
# the the underlying hosts network interface
sudo docker run \
--rm \
--name pg \
--network host \
-e POSTGRES_PASSWORD=postgres \
-p 5432:5432 \
-d postgres:10
# now let's add some persistence for our data so we
# don't lose any state if the container dies. We will
# create a directory "data" to hold the postgres WAL,
# data, logs, config files, and data
mkdir $HOME/github/pg_docker/data
sudo docker run \
--rm \
--name pg \
--network host \
-v $HOME/github/pg_docker/data:/var/lib/postgresql/data/pgdata \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-e POSTGRES_PASSWORD=postgres \
-p 5432:5432 \
-d postgres:10
# the container has no data in it when we pull or build it
# we can add further database initialization and boot strapping
# to our container workflow by using the docker-entrypoint-initdb.d
sudo docker run \
--rm \
--name pg \
--network host \
-v $HOME/github/pg_docker/init:/docker-entrypoint-initdb.d \
-v $HOME/github/pg_docker/data:/var/lib/postgresql/data/pgdata \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-e POSTGRES_PASSWORD=postgres \
-p 5432:5432 \
-d postgres:10