Database dump from another container?

Question is about docker architecture and imo it’s an advanced question.

i have an application running in docker containers. For the sake of simplicity let’s assume there is only a postgresql image and a frontend image. they are linked together just fine and the application is work as intended.

I want to add database dump/restore functionality to the UI.

I’ve read how to dump restore a database running inside a Docker container there are plenty of online sources for that. There are basically two approaches (with volumes or with a data container) but both methods relies on the ability of running docker commands.

However i wonder how should i implement it if i plan to add a dump / restore BUTTON to the UI (aka inside the frontend container) which should have the functionality of being able to save data and give a dump file back to user and reload a data provided by the user via browser interface.
How could the frontend container execute such a function? (there are some very nasty hacks, like you have access to underlying docker commands from within a container (but i consider those security flaws which will be likely purged from upcoming iterations of docker) )

What would be the correct / most efficient approach to do such thing?

Yeah and maybe the most trivial answer like writing custom sql scripts in the application layer implementing pg_dump functionality doesn’t seem to be an efficient solution at all.
[because i want to use the same dump/restore data functionality when updating the software with a shell script as well]

At the end of the day, docker is just a way to run a process. If that process happens to be a database engine, docker doesn’t fundamentally change how it works enough to introduce new options for things like backing up and restoring the database.

Whether or not you are using docker, the best way to back up a database will be the same. If pg_dump is the best backup method for postgres, then you should still use it even if you run postgres in docker.

Hopefully this makes sense.

Cheers!