Docker Community Forums

Share and learn in the Docker community.

Schedule Postgres backup using cron

I would like to periodically backup a Postgres database. I am using Docker Compose, here is the snippet of the postgres container:

    build: ./compose/postgres
      - postgres_data:/var/lib/postgresql/data
      - postgres_backup:/backups

And the Postgres dockerfile:

FROM postgres:9.6

# add backup scripts
ADD /usr/local/bin/backup
ADD /usr/local/bin/restore
ADD /usr/local/bin/list-backups

# make them executable
RUN chmod +x /usr/local/bin/restore
RUN chmod +x /usr/local/bin/list-backups
RUN chmod +x /usr/local/bin/backup

I would like to add a cron task (say backup-cron) that runs every day at midnight. I have read this tutorial but I do not know how to properly integrate it. Any help?