Restore database inside docker container using psql

Commands to restore db from dump using psql inside Docker postgresql container

1) docker-compose run app bundle exec rake db:create (Create Database)

2) Docker ps (get container name)

3) docker exec -it database_container_name_1 bash

4) ls (to see if you have backups directory)

5) mkdir backup ( create backup directory if it doesnt exist)

6) docker cp /Users/ganeshprasad/Downloads/db_copy.sql database_container_name_1:/backup (Copy backup file to backup folder inside container)

7) docker exec -it database_container_name_1 bash

8) psql -U db_owner -d db_name -W < backup/db_copy.sql (Restore the db using psql)

9) sudo rm backup/db_copy.sql (to delete backup)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store