Backup database from within Docker container

I have multiple Django containers running my backend. One which utilizes Celery Beat for scheduled tasks like database backups. I want to dump my database using the django-dbbackup library.

The problem I was facing was that the library uses pg_dump to backup the database obviously which is not installed in my Django environment (and trying to install a new enough version has caused even more problems).

Is there a way for my Django container to connect to my PostgreSQL database container, generate a backup, compress it and upload the file to my object storage? I would need the file to be available within my Django container for all that but I can't seem to find a way that would allow me to actually dump the database without having to install Postgres inside my Django container as well.

I'm using Postgres 15.3-alpine for my container which is why I couldn't just use the postgres version that was already available in the apt repository.

Back to Top