Restore a database backup into a Postgres Docker container

Lets say you have a Postgres database running in a Docker container and you want to restore an sql database backup into it.

If you have Postgres installed locally you will have psql available on your machine. If you don’t have Postgres locally installed its a little more tricky.


cat databaseBackup.sql | docker exec -i pgDockerContainerName psql -U databaseUserName -d databaseName

That causes the content of your sql backup to be piped into the “docker exec” command. Docker exec lets you run a command within a container. The command being run is psql and it receives and runs your sql.