BotNetwork

Docker for bots: images, Compose, secrets and health checks

Containers make deploys repeatable. Bots still need correct signal handling and secret injection.

Guide1 min readUpdated

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

  1. Multi-stage builds so build tools never ship in the runtime image.
  2. Non-root user inside the image.
  3. STOPSIGNAL SIGTERM and handle SIGTERM so Telegram/Discord sessions close cleanly.
  4. Health check on webhook bots (/healthz) for orchestrators.
  5. 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.

Related comparisons and tools