Docker Deployment
Docker Deployment
Section titled “Docker Deployment”Docker is the recommended way to deploy Alita Robot. The provided docker-compose.yml includes all required services with optimized configurations for production use.
Prerequisites
Section titled “Prerequisites”- Docker 20.10 or higher
- docker compose v2 (comes with Docker Desktop)
- A Telegram bot token from @BotFather
- Your Telegram user ID (get it from @userinfobot)
Quick Start
Section titled “Quick Start”-
Clone the repository
Terminal window git clone https://github.com/divkix/Alita_Robot.gitcd Alita_Robot -
Copy and configure environment variables
Terminal window cp sample.env .envEdit
.envwith your configuration. At minimum, set: BOT_TOKEN, OWNER_ID, MESSAGE_DUMP. -
Start all services
Terminal window docker compose up -d
Docker Compose Configuration
Section titled “Docker Compose Configuration”The docker-compose.yml deploys three services:
# Production Docker Compose for Alita Robot# Uses pre-built images from GHCR
services: alita: image: ghcr.io/divkix/alita_robot:latest container_name: alita-robot restart: always environment: DATABASE_URL: postgresql://alita:alita@postgres:5432/alita REDIS_ADDRESS: redis:6379 REDIS_PASSWORD: redis AUTO_MIGRATE: "false" USE_WEBHOOKS: "true" HTTP_PORT: "8080" DROP_PENDING_UPDATES: "true" BOT_TOKEN: ${BOT_TOKEN} OWNER_ID: ${OWNER_ID} MESSAGE_DUMP: ${MESSAGE_DUMP} WEBHOOK_DOMAIN: ${WEBHOOK_DOMAIN} WEBHOOK_SECRET: ${WEBHOOK_SECRET} ports: - "8080:8080" depends_on: postgres: condition: service_healthy redis: condition: service_healthy healthcheck: test: ["CMD", "/app/alita_robot", "--health"] interval: 30s timeout: 10s retries: 3 deploy: resources: limits: memory: 1G cpus: "1.0" reservations: memory: 256M cpus: "0.25"
postgres: image: postgres:17-alpine container_name: alita-postgres restart: always environment: POSTGRES_USER: alita POSTGRES_PASSWORD: alita POSTGRES_DB: alita POSTGRES_INITDB_ARGS: "--encoding=UTF8 --locale=C" volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U alita -d alita"] interval: 10s timeout: 5s retries: 5 deploy: resources: limits: memory: 512M cpus: "0.5"
redis: image: redis:7-alpine container_name: alita-redis restart: always command: redis-server --requirepass redis healthcheck: test: ["CMD", "redis-cli", "-a", "redis", "ping"] interval: 10s timeout: 5s retries: 5 deploy: resources: limits: memory: 256M cpus: "0.25"
volumes: postgres_data:Service Descriptions
Section titled “Service Descriptions”alita (Bot Service)
Section titled “alita (Bot Service)”The main Telegram bot service.
| Configuration | Value | Description |
|---|---|---|
| Image | ghcr.io/divkix/alita_robot:latest | Pre-built image from GitHub Container Registry |
| Port | 8080 | HTTP server for health, metrics, and webhooks |
| Memory Limit | 1GB | Maximum memory allocation |
| Memory Reservation | 256MB | Guaranteed minimum memory |
| CPU Limit | 1.0 | Maximum CPU cores |
| CPU Reservation | 0.25 | Guaranteed minimum CPU |
postgres (Database)
Section titled “postgres (Database)”PostgreSQL 17 with Alpine Linux for a minimal footprint.
| Configuration | Value | Description |
|---|---|---|
| Image | postgres:17-alpine | PostgreSQL 17 on Alpine Linux |
| Memory Limit | 512MB | Maximum memory allocation |
| Encoding | UTF8 | Database character encoding |
| Locale | C | Collation locale |
Data is persisted in a Docker volume named postgres_data.
redis (Cache)
Section titled “redis (Cache)”Redis for caching and session management.
| Configuration | Value | Description |
|---|---|---|
| Image | redis:7-alpine | Redis 7 on Alpine Linux |
| Memory Limit | 256MB | Maximum memory allocation |
| Authentication | Password protected | Uses REDIS_PASSWORD env var |
Environment Variables
Section titled “Environment Variables”Set these in your .env file or pass them to docker-compose:
# RequiredBOT_TOKEN=your_bot_token_hereOWNER_ID=your_telegram_idMESSAGE_DUMP=-100xxxxxxxxxx
# For webhook mode (production)WEBHOOK_DOMAIN=https://your-domain.comWEBHOOK_SECRET=your-random-secretFor a complete list of environment variables, see the Environment Reference.
Resource Limits
Section titled “Resource Limits”The compose file includes recommended resource limits:
| Service | Memory Limit | CPU Limit | Use Case |
|---|---|---|---|
| alita | 1GB | 1.0 | Handles bot traffic |
| postgres | 512MB | 0.5 | Database operations |
| redis | 256MB | 0.25 | Caching |
For high-traffic deployments, increase these limits:
deploy: resources: limits: memory: 2G cpus: "2.0"Updating the Bot
Section titled “Updating the Bot”-
Pull the latest images
Terminal window docker compose pull -
Recreate containers with new images
Terminal window docker compose up -d -
Optional: Remove old images
Terminal window docker image prune -f
Viewing Logs
Section titled “Viewing Logs”docker compose logs -fdocker compose logs -f alitadocker compose logs --tail=100 alitadocker compose logs -f postgresCommon Operations
Section titled “Common Operations”Restart the bot
Section titled “Restart the bot”docker compose restart alitaStop all services
Section titled “Stop all services”docker compose downStop and remove volumes
Section titled “Stop and remove volumes”docker compose down -vAccess PostgreSQL shell
Section titled “Access PostgreSQL shell”docker compose exec postgres psql -U alita -d alitaAccess Redis CLI
Section titled “Access Redis CLI”docker compose exec redis redis-cli -a redisHealth Checks
Section titled “Health Checks”{ "status": "healthy", "checks": { "database": true, "redis": true }, "version": "2.17.24", "uptime": "24h30m15s"}Troubleshooting
Section titled “Troubleshooting”Container keeps restarting
Section titled “Container keeps restarting”Check the logs for error messages:
docker compose logs alitaCommon issues:
- Invalid
BOT_TOKEN MESSAGE_DUMPchannel ID doesn’t start with-100- Database connection failed (wait for postgres to be ready)
Database connection errors
Section titled “Database connection errors”Ensure postgres is healthy before alita starts:
docker compose psThe postgres container should show healthy status.
Webhook not working
Section titled “Webhook not working”- Ensure
WEBHOOK_DOMAINis set correctly (must includehttps://) - Check that
WEBHOOK_SECRETis configured - Verify port 8080 is accessible externally
See Webhooks Guide for detailed setup.