Automated Docker Self-Updating Agent with Email Approval - n8n Workflow

Use this robust n8n workflow to automate Docker-based n8n updates securely. Features scheduled checks, digest comparison, and required email approval before executing critical SSH commands.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • System administrators managing self-hosted n8n instances via Docker Compose.

  • DevOps professionals needing secure, pre-approved automation for critical software updates.

  • Users looking for reliable n8n templates for server maintenance and version control.

  • Anyone who wants to ensure their n8n environment is always running the latest, approved version without manual intervention.

Overview

Maintaining a self-hosted application like n8n requires regular updates to benefit from new features and security patches. However, automated updates should never run without oversight. This highly secure and efficient n8n workflow solves this challenge by acting as a controlled self-updating agent.

The automation initiates a check every three days (customizable using the n8n trigger), comparing the currently running Docker image digest against the latest digest on Docker Hub without pulling the image—saving bandwidth and time. If an update is detected, the n8n node responsible for emailing sends a request for explicit approval. Only when the user clicks 'Approve' will the subsequent SSH n8n node execute the safe update commands, ensuring complete control over the deployment schedule. This is a critical n8n workflow designed for stability and security.

How it Works

The n8n workflow follows a strict, multi-stage approval and execution process:


  1. Scheduled Check: The n8n trigger, configured as a Schedule Trigger n8n node, starts the process every 72 hours (3 days).

  2. Version Retrieval (SSH): The workflow uses SSH n8n nodes to connect to the host server and retrieve the current running n8n version and the local Docker image digest (RepoDigest).

  3. Remote Check (HTTP Request): An HTTP Request n8n node queries Docker Hub’s registry API to fetch the remote digest for the :latest tag, ensuring the check is bandwidth-efficient.

  4. Data Preparation: A Set n8n node prepares the comparison data, determining if an updateavailable flag is true or false based on the digest comparison.

  5. Conditional Flow: An If n8n node checks the updateavailable status. If no changes are found, the workflow ends silently. If an update is detected, it proceeds to the approval step.

  6. Approval Request (Email Send): The Email Send n8n node uses the 'Send and Wait for Approval' feature. It sends a formatted email containing the current and new version information, along with 'Approve' and 'Decline' buttons. The workflow pauses until a response is received.

  7. Approval Branching: A subsequent If n8n node determines the user’s choice. If declined, the workflow terminates safely. If approved, the update process begins.

  8. Update Script Management (SSH): The automation verifies the existence of a dedicated update script (update_docker.sh) via SSH. If the script is missing, a new SSH n8n node generates the file containing the necessary docker compose pull, docker compose down, and docker compose up -d commands, prefixed with a 30-second sleep timer.

  9. Execution (SSH): The final SSH n8n node executes the script in the background using nohup and &. The 30-second delay ensures the n8n workflow completes its current execution successfully before the n8n container restarts, guaranteeing a graceful shutdown of the initiating session.

Installation Guide

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


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

  2. SSH Credentials Setup: Create a new SSH Password credential set within n8n. This must be configured to connect to your Docker host server. Ensure you have the Host IP, Port (usually 22), Username (e.g., root), and Password/Key.

  3. SMTP Credentials Setup: Configure a new SMTP credential set. This is used by the Email Send n8n node to request approval. Input your SMTP Host, Port, Username, and Password.

  4. Node Configuration:

Select the Ask For Approval to Update n8n node and update the To Email and From Email fields to your administrative email addresses.
Verify all SSH n8n node steps are linked to the correct SSH credential you created.

  1. Docker Host Setup: Ensure your n8n installation uses Docker Compose and is located at the expected path (e.g., /opt/n8n-docker-caddy), as specified in the script creation logic.

  2. Activation: Enable the Schedule Trigger n8n node. Run a manual test first to confirm email receipt and SSH connectivity before letting the n8n workflow run automatically.

Node Details

Schedule Trigger: This n8n trigger sets the schedule for the update check. Configured to run every 3 days at 16:00 UTC, ensuring timely, yet infrequent, update checks.
SSH Node (Get Current n8n Version/Digest, Check Script, Create Script, Execute Script): Multiple SSH n8n nodes are fundamental to this n8n workflow. They are used to securely run remote commands on the Docker host server. Key configurations include dynamic commands (docker exec n8n --version, digest retrieval commands, and the final nohup execution command) and specific working directories (/root).
HTTP Request (Get Remote Image Digest): Queries Docker Hub API to get the latest digest. This n8n node operates without needing Docker installed on the n8n host itself, only relying on API access.
Set Node (Prepare Update Data): An essential logic n8n node that aggregates data from the version checks and calculates the boolean value update_available by comparing the local and remote digests.
Email Send Node (Ask For Approval to Update): Uses SMTP credentials to send a rich HTML email detailing the update status. Crucially, it uses the sendAndWait operation with approval options, transforming this into a human-in-the-loop n8n workflow step.
If Nodes (If No Changes, If Approved, If File Exists): These n8n nodes control the flow based on dynamic data. They ensure the email is only sent if an update exists, and the SSH update commands are only executed if explicit approval is granted.

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all

Featured*