How to generate a Postgresql Dump from a Docker container?

Cesar Augusto Nogueira picture Cesar Augusto Nogueira · May 11, 2015 · Viewed 38.9k times · Source

I would like to have a way to enter into the Postgresql container and get a data dump from it.

Answer

Cesar Augusto Nogueira picture Cesar Augusto Nogueira · May 11, 2015

Use the following command from a UNIX terminal:

docker exec <container_name> pg_dump <schema_name> > backup

The following command will dump only inserts from all tables:

docker exec <container_name> pg_dump --column-inserts --data-only  <schema_name> > inserts.sql