-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72575a0
commit 8da499d
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,46 @@ | ||
#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 | ||
|