Docker Container Management Bot with AI Log Debugging - n8n Workflow

Leverage this powerful n8n workflow to monitor Docker containers via webhooks and manage them using a Telegram bot. Features AI-powered log analysis via OpenAI and remote SSH commands.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • DevOps Engineers and System Administrators managing self-hosted Docker environments.

  • Users who need remote container management via a secure instant messaging platform.

  • Individuals looking for advanced n8n templates integrating AI debugging into infrastructure management.

  • Anyone requiring automated webhook responses from monitoring services like Uptime Kuma using an n8n trigger.

Overview

This advanced n8n workflow is designed to centralize Docker infrastructure management and monitoring. It addresses the common pain point of diagnosing container failures by integrating an AI model (via the n8n OpenAI node) directly into the operational flow. The workflow has two primary interfaces: an external webhook for proactive monitoring alerts (e.g., container crash notifications) and a Telegram bot for reactive, on-demand commands (like fetching logs, checking status, or performing restarts). By using the SSH n8n node, it securely executes Docker commands on a remote server, while the AI component provides expert, structured analysis of complex log files, transforming raw data into actionable insights. This robust n8n automation significantly reduces downtime and accelerates debugging cycles, proving the power of a well-configured n8n workflow.

How it Works

The entire flow leverages two main n8n trigger mechanisms:


  1. Monitoring Alert Flow: The process begins with a Webhook n8n trigger. When an external monitoring service reports a change in a container's status, the flow checks the state. If the container is not 'running', an ERROR Message is instantly sent via Telegram, offering actionable inline buttons (Logs and Restart) corresponding to the problematic container.

  2. User Command Flow: When a user interacts with the bot via the Telegram n8n trigger, the message is passed to a Switch n8n node for command routing. A Code n8n node (Extract the Service Name) first parses the command to identify the target container.

  3. Log Analysis: If the user sends a 'logs' command, the SSH n8n node executes docker logs --tail 100. The resulting output is forwarded to the Message a model (OpenAI) n8n node. This node uses a highly customized prompt to act as a senior IT specialist, analyzing the raw logs and generating a structured report (Summary, Root Cause, Recommended Steps). This detailed analysis is then delivered to the user via a Telegram n8n node.

  4. Restart & Status: If the command is 'restart', the SSH n8n node attempts to restart the container. An If n8n node confirms the success or failure based on SSH output errors. For the 'status' command, the SSH n8n node executes docker ps to list all running containers and their status, sending the formatted list back to the user.

  5. Update Automation: The 'update' command triggers the execution of a custom shell script (update-all-docker-compose.sh) via the SSH n8n node. The output of this script is then parsed by a Python Code n8n node to generate a clean update summary, which is sent back to the user, confirming which images were updated. This comprehensive n8n workflow ensures full remote control and intelligent diagnostics.

Installation Guide

To deploy this powerful n8n workflow, follow these setup steps:


  1. Import: Import the provided n8n templates JSON into your n8n instance.

  2. Credentials for n8n node:

Telegram: Set up the required credentials for the Telegram n8n node (Bot Token and Chat ID). You must replace the hardcoded Chat ID (8209283663) in all Telegram nodes.
SSH: Configure your SSH credentials (using key-pair is highly recommended) to allow the SSH n8n node to connect and execute Docker commands on your server.
* OpenAI: Set up the OpenAI credential needed for the Message a model n8n node.

  1. Custom Script: Ensure the server hosting your Docker containers has the required custom script (./update-all-docker-compose.sh) available and executable, matching the parsing requirements of the Code in Python (Beta) n8n node.

  2. Activate Webhook: Activate the Webhook n8n trigger and copy the generated URL. Configure this URL in your external monitoring tool (e.g., Uptime Kuma) as the target for failure alerts.

  3. Activation: Ensure this n8n workflow is marked as Active to enable the functionality of all n8n trigger and action nodes.

Node Details

Webhook (n8n trigger):
Function: Serves as the passive n8n trigger, listening for container status updates from external monitoring services.
Key Configuration: Accepts POST requests.
Telegram Trigger (n8n trigger):
Function: The interactive n8n trigger, initiating the flow based on user commands received via the Telegram bot.
Key Configuration: Listens for message updates.
Switch n8n node:
Function: Routes the execution flow based on the content of the Telegram message (e.g., matching 'logs', 'restart', 'status', or 'update').
Key Configuration: Compares the lowercased message text.
SSH n8n node (get logs):
Function: Executes the command docker logs --tail 100 [service name] on the remote host to retrieve diagnostic information.
Key Configuration: Dynamic command expression using data from the Extract the Service Name Code n8n node.
OpenAI n8n node (Message a model):
Function: This crucial n8n node performs advanced log analysis, using a detailed system prompt to interpret the raw Docker output and provide structured debugging insights.
Key Configuration: Uses gpt-4.1-mini model, feeding log output via ={{ $('get logs').item.json.stdout }}.
Code in Python (Beta) n8n node:
Function: Parses the structured output of the shell update script, translating complex update logs into a clean, consumable message for the Telegram user interface.
Key Configuration: Custom Python script using re and json libraries for string parsing.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by
Malte
Malte

Featured*