Cron Container
Running a container on a schedule using Cron Triggers
To launch a container on a schedule, you can use a Workers Cron Trigger.
For a full example, see the Cron Container Template ↗.
Use a cron expression in your Wrangler config to specify the schedule:
{ "name": "cron-container", "main": "src/index.ts", "triggers": { "crons": [ "*/2 * * * *" // Run every 2 minutes ] }, "containers": [ { "class_name": "CronContainer", "image": "./Dockerfile" } ], "durable_objects": { "bindings": [ { "class_name": "CronContainer", "name": "CRON_CONTAINER" } ] }, "migrations": [ { "new_sqlite_classes": [ "CronContainer" ], "tag": "v1" } ]}
name = "cron-container"main = "src/index.ts"
[triggers]crons = [ "*/2 * * * *" ]
[[containers]]class_name = "CronContainer"image = "./Dockerfile"
[[durable_objects.bindings]]class_name = "CronContainer"name = "CRON_CONTAINER"
[[migrations]]new_sqlite_classes = [ "CronContainer" ]tag = "v1"
Then in your Worker, call your Container from the "scheduled" handler:
import { Container, getContainer } from "@cloudflare/containers";
export class CronContainer extends Container { sleepAfter = "5m"; manualStart = true;}
export default { async fetch(): Promise<Response> { return new Response( "This Worker runs a cron job to execute a container on a schedule.", ); },
async scheduled( _controller: any, env: { CRON_CONTAINER: DurableObjectNamespace<CronContainer> }, ) { await getContainer(env.CRON_CONTAINER).startContainer({ envVars: { MESSAGE: "Start Time: " + new Date().toISOString(), }, }); },};
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-