Importing & Exporting PSQL Database Dump using Docker

Published: (January 9, 2026 at 04:40 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

Prerequisites

  • A running PostgreSQL Docker container.
  • Your SQL dump file available on the host.

Verify the container is running:

docker ps

You should see your PostgreSQL container listed (e.g., exampledb).

Importing a Dump File into the Container

Copy the dump file from the host into the container:

docker cp path_of_dump_file.sql :/tmp/

Example

docker cp ~/Downloads/example_db.sql exampledb:/tmp/example_db.sql

If successful, Docker prints a confirmation such as:

Successfully copied 23MB to exampledb:/tmp/example_db.sql

The file is now inside the container and can be used to populate the database.

Exporting (Dumping) the Database from Docker

Create a dump of the database and save it on the host machine:

docker exec  pg_dump -U   > file.sql

Example

docker exec exampledb pg_dump -U root exampledb > example_db_dump.sql

The command generates example_db_dump.sql on your local system, containing a full backup of the database.

Back to Blog

Related posts

Read more »

Hello, Newbie Here.

Hi! I'm falling back into the realm of S.T.E.M. I enjoy learning about energy systems, science, technology, engineering, and math as well. One of the projects I...