Look At Upgrading Postgres In Docker ==================================== The standard Docker images for Postgres have the following issues wrt in place upgrades: - Only 1 version of Postgres binaries - Cannot stop Postgres (stops container) To get around this a custom image that has: - 2 versions of Postgres binaries (e.g version 10 and 11) - runs top (or tail -f etc) as its ENTRYPOINT so that Postgres is stopped Run a container with this image using 2 volumes (one for the old install one for the new); $ docker run \ --detach \ --name=mig-postgres \ --volume=/srv/docker/volumes/test-postgres/datadir10:/var/lib/postgresql/data \ --volume=/srv/docker/volumes/test-postgres/datadir11:/var/lib/postgresql/data11 \ migpostgres $ docker exec -it mig-postgres bash # chown postgres:postgres /var/lib/postgresql/data11 # su - postgres postgres $ /usr/lib/postgresql/11/bin/initdb -D /var/lib/postgresql/data11 postgres $ /usr/lib/postgresql/11/bin/pg_upgrade \ --old-bindir=/usr/lib/postgresql/10/bin \ --new-bindir=/usr/lib/postgresql/11/bin \ --old-datadir=/var/lib/postgresql/data \ --new-datadir=/var/lib/postgresql/data11 \ --old-port=5432 \ --new-port=5433 \ --check (run again w/o --check if ok) postgres $ echo "listen_addresses='*'" >> /var/lib/postgresql/data11/postgresql.conf postgres $ cp /var/lib/postgresql/data/pg_hba.conf \ /var/lib/postgresql/data11 postgres $ exit # exit $ docker container stop mig-postgres $ docker run \ --detach \ --name=test-postgres11 \ --volume=/srv/docker/volumes/test-postgres/datadir11:/var/lib/postgresql/data \ --publish 5432:5432 \ postgres:11