This project implements a Telegram bot that interacts with Docker containers using the Docker SDK for Python. The bot allows users to start specific containers, list containers, run containers, get container logs, and stop containers through Telegram commands.
Containerization has revolutionized software deployment and management, and in this tutorial, we demonstrate how to leverage the Telegram Python module and the Docker SDK to control Docker containers programmatically. By integrating the Telegram platform with Docker, you can automate container operations, monitor containers, and interact with them using a chatbot interface. Contents
The repository includes the following files:
1. Python script demonstrating the integration of the Telegram Python module and Docker SDK to control Docker containers. This script provides examples of retrieving container lists, stopping all containers.
2. README.md: This README file providing an overview of the repository and the video tutorial.
To get started with the code examples in this repository, follow these steps:
git clone https://github.com/satishsverma/dockerSDK_telegeram_python.git
cd dockerSDK_telegeram_python
.env-example to .envmv .env-example .env
And set up environment variables:
TELEGRAM_BOT_TOKEN= "Your Telegram Bot Token"
CONTAINERS_TO_SKIP= "Comma-separated list of container names to skip (optional)"
Note:- CONTAINERS_TO_SKIP: This environment variable can be set to a comma-separated list of container names that should not be affected by the bot's commands.
To run this bot in a Docker container:
docker compose build
docker compose up
/help: Get help and list of commands./list: Get a list of all containers./start CONTAINER_NAME: Start a specific container./logs CONTAINER_NAME -n 10 : Get container logs default 10 lines./stop CONTAINER_NAME: Container name to stop or use 'all' to stop all containers./compose - Start containers from github repo with branch./del CONTAINER_NAME: Delete a container.Note: Mounting /var/run/docker.sock allows the bot to interact with the Docker daemon on the host.
CONTAINERS_TO_SKIP list to prevent unintended actions on critical containers.The integration of the Telegram Python module and Docker SDK opens up various applications, including:
Remote container management: Control Docker containers from anywhere by sending commands via the Telegram chatbot. Automation of container operations: Build scripts or bots that automatically start, stop, or restart containers based on specific events or triggers. Deployment orchestration: Initiate deployments, spin up new containers, and manage container clusters through Telegram messages. Monitoring and notifications: Receive real-time updates on container status, resource usage, and error alerts via Telegram, enabling prompt response to issues. Interactive container management: Provide a user-friendly interface for users to interact with Docker containers through a Telegram chatbot.
Contributions are welcome! Please feel free to submit a Pull Request.
Content type
Image
Digest
sha256:4ecce0328…
Size
122.3 MB
Last updated
about 2 years ago
docker pull satishsverma/telegram-bot