How to create a database backup using docker-compose
The number of downvotes on the link that is mentioned in the question could indicate that there are issues with the instructions.

Perhaps one could use native commands to backup the database. For example, this answer shows how to backup a postgres database that runs in docker using the pg_dump command.