Step-by-Step Guide to Backing Up and Restoring PostgreSQL in Docker
$containerName = "my_postgres_container";
$dbUser = "postgres_user";
$database = "my_database";
docker exec -t $containerName pg_dumpall -c -U $dbUser > database-dump.sql
# stop the container and remove the data volume
# start the container normally
cat database-dump.sql | docker exec -i $containerName psql -U $dbUser -d $database