Named Volumes
Assignment
- Database upgrade with containers
- Create a postgres container with named volume
psql
using version 9.6.4
- Use Docker Hub to learn VOLUME path and versions needed to run it
- Check logs, stop container
- Create a new postgres container with same named volume using
9.6.5
- Check logs to validate
- (this only works with patch versions, most SQL DB's require manual commands to upgrade DB's to major/minor versions, i.e. it's a DB limitation not a container one)
Solution
~> docker container run -d --name psql -v psql:/var/lib/postgresql/data postgres:9.6.4
0b0ee853371be32b8a1bab44f651385cd89c20eb2c759651e0113cb9456e0837
~> docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0b0ee853371b postgres:9.6.4 "docker-entrypoint..." 7 seconds ago Up 5 seconds 5432/scp psql
~> docker container logs -f psql
...
PostgreSQL init process complete; ready for start up.
LOG: database system was shut down at 2017-10-01 11:04:59 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
~> docker container stop psql
psql
~> docker container run -d --name psql2 -v psql:/var/lib/postgresql/data postgres:9.6.5
98c249076a897879f3e87ede39eedc059e0dbd2ab83094677c6fc7d1331bf45e
~> docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
98c249076a89 postgres:9.6.5 "docker-entrypoint..." 29 seconds ago Up 27 seconds 5432/tcp psql2
0b0ee853371b postgres:9.6.4 "docker-entrypoint..." 5 minutes ago Exited (0) About a minute ago psql
~> docker volume ls
DRIVER VOLUME NAME
local psql
~> docker container logs psql2
LOG: database system was shut down at 2017-10-01 11:09:15 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started