Workshop Persistance Storage and Volume
$ docker run -d --name postgres_db -p 5432:5432 -v pg_data:/var/lib/postgresql/data postgres:10.1-alpine
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
692828b21f0d postgres:10.1-alpine "docker-entrypoint..." 11 seconds ago Up 13 seconds 0.0.0.0:5432->5432/tcp postgres_db
$ psql -h localhost -p 5432 -U postgres
psql (10.1)
Type "help" for help.
postgres=#
or go inside the container (docker exec -it) interact with command line
$ docker exec -it 692828b21f0d /bin/bash
bash-4.3# psql -U postgres
psql (10.1)
Type "help" for help.
postgres=#
postgres=# create database db1 with owner postgres;
CREATE DATABASE
postgres=# \q
inspect and test persistence of the volume
$ docker inspect 692828b21f0d
...
"Mounts": [
{
"Type": "volume",
"Name": "pg_data",
"Source": "/var/lib/docker/volumes/pg_data/_data",
"Destination": "/var/lib/postgresql/data",
"Driver": "local",
"Mode": "z",
"RW": true,
"Propagation": ""
}
],
...
$ docker rm -f 692828b21f0d
$ docker run -d --name postgres_db2 -p 5432:5432 -v pg_data:/var/lib/postgresql/data postgres:10.1-alpine
abdf7976e35faf8c920128a6cfbeae82aff2f843e1e96313f3cb555586cb7f5f
$ docker exec -it abdf7976e35fa bash
bash-4.3# psql -U postgres
psql (10.1)
Type "help" for help.
postgres=# show databases;
ERROR: unrecognized configuration parameter "databases"
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
db1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
postgres=#
docker volume command
$ docker volume list
DRIVER VOLUME NAME
local pg_data
$ $ docker volume rm pg_data
Error response from daemon: unable to remove volume:
remove pg_data: volume is in use - [abdf7976e35faf8c920128a6cfbeae82aff2f843e1e96313f3cb555586cb7f5f]
extra -e POSTGRES_PASSWORD=mysecretpassword
$ docker run -d --name postgres_db2 -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword
-v pg_data:/var/lib/postgresql/data postgres:10.1-alpine
location of linux file system for linux on mac
$ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
# ls -ltrh /var/lib/docker/volumes/
total 28
drwxr-xr-x 3 root root 4.0K Dec 3 14:37 pg_data
-rw------- 1 root root 32.0K Dec 3 14:37 metadata.db