Why Docker for bots
A bot is a long-running process with secrets and usually one or two dependencies (Redis, Postgres). Docker (or any OCI container) gives you the same filesystem on a laptop, a VPS and a PaaS.
Minimal practices
- Multi-stage builds so build tools never ship in the runtime image.
- Non-root user inside the image.
STOPSIGNAL SIGTERMand handle SIGTERM so Telegram/Discord sessions close cleanly.- Health check on webhook bots (
/healthz) for orchestrators. - Secrets via env at runtime, never
COPY .env.
Long polling vs webhooks
- Long polling / Discord Gateway: one container replica unless you shard deliberately.
- Webhooks: horizontally scalable behind a load balancer if you deduplicate updates.
Compose sketch
Run the bot plus Redis for rate limits or session state. Publish only the webhook port. Keep Postgres credentials out of the Compose file that you commit; use an env file that is gitignored.