Prerequisites
- Docker installed on your system
- Bot token from @BotFather
- (Optional) Telegram API credentials from my.telegram.org
Quick Start
Build the Docker image
Build the image using the included Dockerfile:The image uses
ghcr.io/astral-sh/uv:python3.13-trixie-slim as the base and leverages Docker layer caching for fast rebuilds.Configure environment variables
Create a Set the required variables:Required:
.env file based on .env.example:BOT_TOKEN- Your Telegram bot token
When running a single container, ensure
TG_SERVER is reachable from inside the container. If you set TG_SERVER=http://telegram-bot-api:8081, you must also run a telegram-bot-api container and place both on the same Docker network.Single Container vs Docker Compose
Single Container
Pros:- Simple setup for testing
- Minimal resource usage
- Quick to start and stop
- Must use public Telegram API (rate limited)
- No database persistence (unless configured separately)
- Manual network configuration needed for local Bot API
Docker Compose
Pros:- Local Telegram Bot API server (faster, avoids rate limits)
- PostgreSQL database included (persistent statistics)
- All services networked automatically
- Production-ready setup
- Requires more system resources
- More configuration options to understand
Dockerfile Details
The Dockerfile uses a multi-stage approach for optimal caching:- Uses
uvfor fast dependency resolution - Separates dependency and source layers for better caching
- Installs
mainextra dependencies (includes yt-dlp, Pillow, curl_cffi) - Unbuffered Python output for real-time logs
Environment Variables
| Variable | Required | Description | Default |
|---|---|---|---|
BOT_TOKEN | Yes | Telegram bot token from @BotFather | - |
TG_SERVER | No | Telegram API endpoint | https://api.telegram.org |
TELEGRAM_API_ID | Conditional* | API ID from my.telegram.org | - |
TELEGRAM_API_HASH | Conditional* | API hash from my.telegram.org | - |
DB_URL | No | PostgreSQL connection string | SQLite (file-based) |
TG_SERVER=http://telegram-bot-api:8081)
Troubleshooting
Container exits immediately
Check the logs for error messages:- Invalid
BOT_TOKEN TG_SERVERpointing to unreachable host- Missing
TELEGRAM_API_ID/TELEGRAM_API_HASHwhen using local Bot API
Cannot reach telegram-bot-api service
Example with manual networking:Next Steps
Docker Compose
Deploy the full stack with all services
Local Development
Run the bot locally without Docker

