How do I can upgrade Docker Postgresql without removing existing data?

10,241

To preserve data across a docker container a volume is required. This volume will mount directly onto the file system of the container and be persevered when the container is killed. It sounds though that the container was created without a volume attached. The best way to get that data is to use copy the data folder for the container and move to the host file system. Then create a docker container with the new image. Copy the data directory to the running container's data directory in this case pgdata:/var/lib/postgresql/data

docker cp [containerID]:/var/lib/postgresql/data /home/user/data/data-dir/
docker stop [containerID]
docker run -it --rm -v pgdata:/var/lib/postgresql/data postgres
docker cp /home/user/data/data-dir [containereID]:/var/lib/postgresql/data

In case that doesn't work i would just dump the current databases, and re-upload them to the new container

Share:
10,241
Blackjack
Author by

Blackjack

Updated on June 14, 2022

Comments

  • Blackjack
    Blackjack almost 2 years

    I am beginner both of docker and postgresql. 

    How do I upgrade docker postgresql 9.5 into 9.6 without losing my  current database?  fyi: im using ubuntu version 14 and docker 17.09 

    Thanks in advance.