-
Notifications
You must be signed in to change notification settings - Fork 9
/
ContainerVolumes.ps1
46 lines (34 loc) · 975 Bytes
/
ContainerVolumes.ps1
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
#run container with persistent volume
docker run -d -p 5432:5432 -v postgres-data:/var/lib/postgresql/data --name postgres1 postgres
#connect to container interactive shell
docker exec -it postgres1 sh
#create db in postgres
createdb -U postgres mydb
#connect to db in postgres
psql -U postgres mydb
#create table in db
CREATE TABLE people (id int, name varchar(80));
#instert data to table
INSERT INTO people (id,name) VALUES (2, 'Onur');
#quit from postgre connection
\q
#quit from container
exit
#delete container
docker rm -f postgres1
#list volumes
docker volume ls
#run new container with existing volume
docker run -d -p 5432:5432 -v postgres-data:/var/lib/postgresql/data --name postgres2 postgres
#connect to containers interactive shell
docker exec -it postgres2 sh
#connect to postgres
psql -U postgres mydb
#get data from postgres
SELECT * FROM people;
\q
exit
#delete container
docker rm -f postgres2
#delete volume
docker volume rm postgres-data