Update Database Containers and Others Reliably
Containers that don't have a built in script
- Stop the application (
docker-compose down)
- Start just the database (
docker-compose up -d db)
- Export all databases on the server into plaintext (
pg_dumpall -U username > data.sql)
- Stop the database (
docker-compose down)
- Remove the contents of the database directory, wherever you’ve mounted in
/var/lib/postgres
- Update the tag you are using, and pull the new container (
postgres:12-alpine → postgres:14-alpine)
- Start just the database (
docker-compose up -d db). This will recreate a fresh database, using the credentials from the environment.
- Import the data into the new database (
psql -U username < data.sql)
- Stop the database container (
docker-compose down)
- Start everything (
docker-compose up -d)
Credits