How migrate physical postgres database data to postgres container

536 Views Asked by At

I have postgres database with stored data. Now i want to change my application to run in a container and reading from earlier stored data in postgres database. But how to create volume with already stored data? A don't want to lose any data. How to achieve it?

1

There are 1 best solutions below

0
Maxim On BEST ANSWER

Better to use pg_dump https://postgrespro.com/docs/postgresql/9.6/app-pgdump

You need to dump a database to file at first

pg_dump mydb > db.sql

After your container is running you need to restore this data from file as

psql -d newdb -f db.sql