This guide covers security best practices for running the Telegram Bot API Docker container in production environments.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ragnarok22/telegram-bot-api-docker/llms.txt
Use this file to discover all available pages before exploring further.
Container Security
Non-root User
The container runs as a non-root user for enhanced security:- User:
botapi - Group:
botapi - All processes run without root privileges
- Data directories are owned by
botapi:botapi
Runtime Security
The Dockerfile implements several security measures:- Minimal runtime image: Alpine Linux base reduces attack surface
- Only necessary dependencies:
libstdc++andlibgccfor runtime - No build tools in final image: Multi-stage build separates build and runtime
- Executable permissions: Entrypoint script uses
--chmod=755for explicit permissions
Credential Management
Required Credentials
Two credentials are required to run the container:| Credential | Purpose | Where to get |
|---|---|---|
TELEGRAM_API_ID | Telegram API application ID | https://my.telegram.org |
TELEGRAM_API_HASH | Telegram API application hash | https://my.telegram.org |
Secure Credential Storage
Use Docker secrets (Swarm/Compose):.gitignore:
Local Mode Security
What is Local Mode?
WhenTELEGRAM_LOCAL=true is set, the server passes the --local flag to telegram-bot-api:
Security Implications
Local mode enables:- Serving files from the local filesystem
- Absolute file paths in
getFileresponses - Bypassing normal file access restrictions
- Potential exposure of sensitive files if bot is compromised
- Directory traversal attacks if not properly isolated
- Larger attack surface for file-based exploits
When to Use Local Mode
✅ Safe scenarios:- Development/testing environments
- Isolated private networks
- Single-tenant deployments with trusted bot code
- Public-facing production environments
- Multi-tenant deployments
- When serving untrusted bot applications
Hardening Local Mode
If you must use local mode:-
Network isolation:
-
Read-only root filesystem:
-
Limit volume mounts:
Volume Permissions
Secure Volume Configuration
The container expects writable access to:/data- Bot data and database/data/logs- Log files/tmp- Temporary files
Sensitive Data Protection
Best practices:-
Encrypt volumes at rest:
-
Restrict host access:
-
Regular backups:
-
Exclude from version control:
Network Security
Recommended Network Configuration
Create isolated network:Firewall Rules
Allow only necessary traffic:Reverse Proxy
For production deployments, use a reverse proxy:Container Security Scanning
Scan for Vulnerabilities
Using Docker Scout:Regular Updates
Pull latest image:Monitoring and Auditing
Enable Audit Logging
Increase log verbosity:Container Resource Limits
Prevent resource exhaustion attacks:Compliance and Hardening
CIS Docker Benchmark
Follow CIS Docker Benchmark guidelines:- ✅ Run as non-root user
- ✅ Use trusted base images (Alpine)
- ✅ Scan images for vulnerabilities
- ✅ Limit container capabilities
- ✅ Use read-only root filesystem where possible
Security Checklist
- Credentials stored securely (not in version control)
-
.envfile has restricted permissions (600) - Container runs as non-root
- Volumes have appropriate permissions
- Network access restricted to necessary ports
- Local mode disabled in production (unless required)
- Regular security scans performed
- Logs monitored for suspicious activity
- Backups encrypted and tested
- Container image kept up to date
Reporting Security Issues
If you discover a security vulnerability:- Do not open a public issue
- Email the maintainer: sasuke.reinier@gmail.com
- Include detailed reproduction steps
- Allow reasonable time for a fix before disclosure