Comprehensive guides for Docker usage, covering management, maintenance, configuration, and optimization.
Updating Postgres in a Docker environment is straightforward once you’ve done it a few times. Follow these steps
docker exec -t <container-name> pg_dumpall -c -U postgres > ./all-data.sql
cat all-data.sql
docker stop <container-name>
Update the Postgres Version
Modify the Postgres version in your compose.yml
file. The latest version can found on Docker Hub - Postgres.
Pull the new Docker Image
Download the latest Postgres image using one of the following commands
docker pull postgres:17-alpine
Or, if compose.yml
is used, run
docker compose pull
Clean Up Old Data
If you used a bind mount, remove the old data, but retain the all-data.sql file. If you utilized a Docker volume, delete that instead.
Start the Updated Container
Relaunch the container with the updated image using one of the following commands
docker run ...
Or, if using Docker Compose
docker compose up -d
cat all-data.sql | docker exec -i <container-name> psql -U postgres