Skip to main content

Restore PG Dump in Docker DB

These steps were originally developed while working on the internal Deepvibe project. This project included several containers that all started together. Because of this, the DB container had to be started alone. You can start a single container from a docker-compose.yml file with multiple containers by passing the container name in the docker compose app, as in:

docker compose up db

Where "db" is the name of the PostgreSQL container in the docker-compose.yml file.

If your DB has active dependencies you must stop them before moving forward.

Restore a PG Dump File

  1. Start your docker DB container: docker compose up db.
  2. In another window, run docker ps to get the CONTAINER ID for the running DB container.
  3. Connect to the PSQL CLI for the container by running the command docker exec -it CONTAINERID psql -U postgres.
  4. Use the command \l to see if the database already exists.
  5. If it exists, drop the database with DROP DATABASE DBNAME;.
  6. Create an empty database with the command CREATE DATABASE DBNAME;.
  7. Exit the CLI with the command \q.
  8. Get the local IP address for that container by running the command docker inspect CONTAINERID | grep IPA.
  9. Restore the database with the command pg_restore -U postgres -d DBNAME -h 172.XX.0.X -1 /path/to/dumpfile.