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