The Telegram Bot API server requires persistent storage for bot data, logs, and temporary files. Understanding how volumes work is essential for data persistence, backups, and troubleshooting.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.
Volume Overview
The Docker image defines one named volume (source atDockerfile:45) and uses several important directories:
/data- Primary working directory for bot data/data/logs- Log file directory/tmp- Temporary files for HTTP operations
Primary Volumes
/data - Bot Data Directory
The main working directory where the server stores all bot-related data. Default value:/data (configurable via TELEGRAM_DIR)
Contains:
- Bot session data (subdirectories named by bot user ID)
- Database files
- Downloaded media and files
- Configuration state
Each bot’s data is stored in a subdirectory within
/data named by its user ID. When migrating between servers, you can copy these subdirectories to preserve bot state./data/logs - Log Files
Directory for server log files. Default log file:/data/logs/telegram-bot-api.log (configurable via TELEGRAM_LOG_FILE)
Mount example:
/data/logs is a subdirectory of /data, mounting /data automatically includes logs.
Accessing logs:
/tmp - Temporary Directory
Directory for HTTP server temporary files. Default value:/tmp (configurable via TELEGRAM_TEMP_DIR)
Usage: Temporary storage for file uploads/downloads during HTTP operations.
Mount example (if needed):
In most cases, you don’t need to mount
/tmp as a volume. The container’s temporary filesystem is sufficient for transient data.Volume Setup
Creating the Data Directory
Before first run, create the data directory and ensure proper permissions:botapi user (source at Dockerfile:35-38), which needs write access to these directories.
Permission Issues
If you encounter permission errors:Data Persistence
Why Volumes Matter
Without a mounted volume, data is stored inside the container’s ephemeral filesystem:- Data is lost when the container is removed
- No easy way to backup or migrate data
- Cannot access logs from the host
Container Lifecycle
With properly mounted volumes, you can safely:- Stop and start the container
- Remove and recreate the container
- Upgrade to a new image version
- Move the data directory to another host
Backup and Migration
Backing Up Bot Data
Simple backup using tar:Restoring from Backup
Migrating Between Servers
To move a bot to a new server:-
On the old server:
-
On the new server:
- Optional - logout from old server first: Before migrating, call the logOut method on the old server to ensure proper update delivery.
Custom Volume Configuration
Using Named Docker Volumes
Instead of bind mounts, you can use Docker named volumes:Custom Directory Paths
Change the internal paths using environment variables:When using custom paths, ensure the directories exist and are writable by the
botapi user inside the container.Monitoring Storage Usage
Check Volume Size
Check Docker Volume Usage
Troubleshooting
Logs Not Appearing
If logs aren’t being written:-
Check directory permissions:
-
Verify the log path inside container:
-
Check for permission errors in container logs:
Data Not Persisting
If data is lost after container restart:-
Verify volume mount:
-
Ensure you’re not removing the volume:
Permission Denied Errors
If the container can’t write to/data:
Best Practices
- Always mount
/data- Never run without a persistent volume in production - Regular backups - Automate backups of your data directory
- Monitor disk usage - Bot data can grow significantly over time
- Use named volumes - For better Docker integration and portability
- Test restores - Periodically verify your backups can be restored successfully
- Separate logs - Consider mounting
/data/logsseparately for log rotation and management - Document your setup - Keep notes on your volume configuration and backup procedures