How to generate a Postgresql Dump from a Docker container?

Use the following command from a UNIX or a Windows 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

I have container named postgres with mounted volume -v /backups:/backups

To backup gziped DB my_db I use:

docker exec postgres pg_dump -U postgres -F t my_db | gzip >/backups/my_db-$(date +%Y-%m-%d).tar.gz

Now I have

user@my-server:/backups$ ls
my_db-2016-11-30.tar.gz