Status Hooks
Execute Workers code in reaction to Container status changes
When a Container starts, stops, and errors, it can trigger code execution in a Worker
that has defined status hooks on the Container
class.
import { Container } from '@cloudflare/containers';
export class MyContainer extends Container { defaultPort = 4000; sleepAfter = '5m';
override onStart() { console.log('Container successfully started'); }
override onStop(stopParams) { if (stopParams.exitCode === 0) { console.log('Container stopped gracefully'); } else { console.log('Container stopped with exit code:', stopParams.exitCode); }
console.log('Container stop reason:', stopParams.reason); }
override onError(error: string) { console.log('Container error:', error); }}
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
-