
Overview
crontab is a little too opinionated for containers—it’s a great little tool, but when run inside of containers it doesn’t grab ENV vars how we’d like it to. Fortunately there’s a Go binary called supercronic that’s a drop-in replacement for containers.
The good news is that it’s pretty easy to get it running on Fly with a little bit of copy and pasting. Let’s get to it.
Create a crontab file
In the root of your project, add acrontab file.
crontab file would something like this:
Install supercronic in the container
The latest releases for supercronic are on GitHub, where they include copy pasta 🍝instructions for getting it in your Dockerfile. As of January 2024, the current version of supercronic is v0.2.29. You’ll want to check the releases page for the latest version, but here’s what it looks like now:
supercronic. Why? Because if you have a cronjob that does something like deliver emails to customers, you only want them to get that once. The last thing you want is them getting as many emails from your services that matches the number of instances you’re running.
Setup a web & cron process
At the bottom of thefly.toml file, add the following:
web process matches up with a service by having this under the [[services]].
web processes that you defined under [processes] will be exposed to the public internet. Your cron process won’t be exposed to the public Internet because it doesn’t need to!
Deploy & scale the new processes
Now that we’ve addedsupercronic to our Dockerfile, put the crontab at the root of our project folder, and reconfigured the fly.toml file, we’re ready to deploy to production.
cron process. Be sure to change web to whatever number you had before.
cron process in a Fly virtual machine. When you fly deploy it will get the latest code changes and reboot the virtual machines.
Resources
Related Reading
- Task scheduling guide with Cron Manager and friends A broader look at scheduling jobs on Fly.io — covers Cron Manager, Supercronic, scheduled Machines, and more.
- Run multiple process groups in an app Explains how to define processes in
fly.toml, run multiple programs (web, cron, workers), scale by group. - App Configuration (
fly.toml) In‑depth look at the config file that orchestrates your services, processes, health checks, etc.