DockeGram is a Telegram bot that allows you to manage Docker containers directly through Telegram messages. With DockeGram, you can start, stop, restart containers, view logs, and monitor container status, all from your Telegram app.
- Start, stop, and restart Docker containers
- View container logs
- List all containers with their current status
- Check if specific containers exist
- Automatic monitoring of container status with alerts for unexpected stops
- User authentication to restrict access to authorized users only
- Docker installed on your host machine
- Telegram Bot Token (obtained from BotFather)
- Telegram User ID of authorized users
- Open Telegram and search for
@BotFather - Start a chat with BotFather and send the command
/newbot - Follow the instructions to create your bot
- Once created, BotFather will provide you with a token. Save this token for later use.
- Send a message to
@userinfoboton Telegram - The bot will reply with your User ID and other information
- Create a
docker-compose.ymlfile with the following content:
version: '3.9'
services:
dockergram:
image: gdagtekin/dockegram:latest
container_name: dockegram
restart: unless-stopped
environment:
- TELEGRAM_BOT_TOKEN=YOUR_BOT_TOKEN
- ALLOWED_USER_IDS=YOUR_USER_ID
- ENABLE_MONITORING=True
- MONITORING_INTERVAL=300
volumes:
- /var/run/docker.sock:/var/run/docker.sock- Replace
YOUR_BOT_TOKENandYOUR_USER_IDwith your actual values - Run the following command in the same directory as your
docker-compose.ymlfile:
docker compose up -ddocker run -d \
--name dockegram \
--restart unless-stopped \
-e TELEGRAM_BOT_TOKEN=YOUR_BOT_TOKEN \
-e ALLOWED_USER_IDS=YOUR_USER_ID \
-e ENABLE_MONITORING=True \
-e MONITORING_INTERVAL=300 \
-v /var/run/docker.sock:/var/run/docker.sock \
gdagtekin/dockegram:latestReplace YOUR_BOT_TOKEN with the token provided by BotFather and YOUR_USER_ID with your Telegram User ID. If you want to allow multiple users, separate their IDs with commas (e.g., 123456789,987654321).
Check your log
docker logs -f dockegram- Clone the repository:
git clone https://github.com/gdagtekin/dockegram.git
cd dockegram- Build the Docker image:
docker build -t dockegram .- Run the container:
docker run -d \
--name dockegram \
--restart unless-stopped \
-e TELEGRAM_BOT_TOKEN=YOUR_BOT_TOKEN \
-e ALLOWED_USER_IDS=YOUR_USER_ID \
-e ENABLE_MONITORING=True \
-e MONITORING_INTERVAL=300 \
-v /var/run/docker.sock:/var/run/docker.sock \
dockegramdocker logs -f dockegramYou can configure Dockegram using the following environment variables:
| Variable | Description | Default |
|---|---|---|
TELEGRAM_BOT_TOKEN |
Your Telegram Bot token | Required |
ALLOWED_USER_IDS |
Comma-separated list of authorized Telegram User IDs | Required |
ENABLE_MONITORING |
Enable automatic container monitoring | False |
MONITORING_INTERVAL |
Monitoring check interval in seconds | 300 |
Dockegram supports two command formats:
/start_container_name- Start a container/stop_container_name- Stop a container/restart_container_name- Restart a container/logs_container_name- Show last 10 logs from a container
/start container_name- Start a container/stop container_name- Stop a container/restart container_name- Restart a container/logs container_name- Show last 10 logs from a container/check container_name- Check if a container exists
/list- List all containers with clickable command links/help- Show help message/info- Show information about the bot environment
- To start a container named "nginx":
/start_nginxor/start nginx - To stop a container:
/stop_nginxor/stop nginx - To view container logs:
/logs_nginxor/logs nginx - To list all containers:
/list
When ENABLE_MONITORING is set to True, Dockegram will periodically check the status of all containers. If a container stops unexpectedly (not manually stopped through the bot), Dockegram will send an alert message to all authorized users.
- The bot only allows commands from users listed in
ALLOWED_USER_IDS - The Docker socket is mounted into the container, which gives the bot full control over your Docker environment
- Only give access to users you trust with full Docker control
Distributed under the AGPLv3 License. See LICENSE.md for more information.
Developed by Gökhan Dağtekin