What Docker changes
Docker packages your runtime and dependencies so the same image can run on your laptop and host. It does not host the bot for you. You still need a machine or container service that keeps the process running.
Start with a bot that already works locally. The examples below assume a TypeScript bot built into dist/index.js, or a Python bot started with bot.py. Adjust those paths and use runtime versions supported by your dependencies.
Build the image
This Node example installs dependencies from a committed lockfile, compiles the project, and leaves development dependencies out of the final image. It uses Node 24; check your bot library’s runtime requirement before copying it.
For Python, install your pinned dependencies and run as a separate application user. Add any native packages your dependencies need; voice bots may also require FFmpeg and Opus.
Run it with Compose
Create a local .env file containing the variables your bot expects, such as DISCORD_TOKEN. Keep it out of Git and restrict access on the host.
A Gateway-only bot does not need a published port. If it stores SQLite files or uploads locally, mount a persistent volume and make sure the application user can write to it. Back up that data separately from the image.
Handle restarts deliberately
- Handle SIGTERM: stop accepting work, finish or requeue jobs, close the Discord client, then exit.
- Use your library’s reconnect handling for short Discord connection failures.
- Keep the previous image available so a failed release can be rolled back.
- Check that only the intended process owns each shard after a deployment.
- Test a host reboot and a restore from backup before relying on the setup.
A health check can report an unhealthy process, but plain Docker Compose does not automatically restart a container just because that check fails. The restart policy responds to process exits. Monitor the actual connection and command behavior too.
For the underlying packaging concepts, see Docker’s Node.js guide. For automated releases, continue with bot CI/CD.