I am trying to run my database in docker which already have some data into it, But when I run it in docker it gives empty .. So how to restore my database in docker PostgreSQL image.
To back up a data volume you can run a new container using the volume you want to back up and executing the tar command to produce an archive of the volume content as described in the docker user guide. In your particular case, the data volume is used to store the data for a MySQL server.
First, Start your docker posgtres container. Then execute the following command:
docker exec -i <CONTAINER> psql -U <USER> -d <DB-NAME> < <PATH-TO-DUMP>
<CONTAINER>
: Container ID or container name<USER>
: User of PostgreSQL DBMS. If you use the standard postgres image with no specific config the user is postgres
<DB-NAME>
: The name of the DB. This DB should already exist. You can create a db when running your postgres container by specifying an environment variable named POSTGRES_DB
<PATH-TO-DUMP>
: Specify here the path to your dump fileExample:
docker exec -i mypostgres psql -U postgres -d mydb < backup.sql
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With