Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 693
Blackjack Avatar asked Oct 10 '17 17:10

Blackjack


People also ask

Where is Postgres Docker data stored?

User Defined Volume To circumvent this issue, we can use the information we gathered earlier that showed us that the volume is mounted at /var/lib/postgresql/data. Inside the container, this directory is where Postgres stores all the relevant tables and databases.


1 Answers

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

like image 116
will7200 Avatar answered Oct 01 '22 06:10

will7200