Is triggering a Docker container from n8n’s Execute Command node a recommended approach?

Hi, I’m using n8n (in Docker) and I’m trying to build the following workflow:

  • n8n runs in a container (always on)

  • a Python container exists in the same docker-compose setup (used on demand)

  • both containers share a Docker volume

Goal:

At a scheduled time, n8n should:

  1. Trigger a Python container execution

  2. The Python script generates an Excel file into the shared volume

  3. n8n reads the file and sends emails

Issue:

I initially thought I could use the Execute Command node to run something like:

docker start python-container
or
docker run python-image

But it seems the Execute Command node runs inside the n8n container, not on the host, so it cannot control Docker directly.

Question:

What is the recommended way to trigger a Docker container from n8n? Am I missing the right architectural approach? Should I consider a different architecture instead?
I am a Docker and n8n beginner :cry:

HI @handsome_programmer Welcome!
Naw! that execute command node itself also runs inside the n8n container so you cannot actually do a lot with it, but i would recommend reading this:

@handsome_programmer skip the Execute Command entirely, just add a tiny Flask endpoint to your Python container that kicks off the script and have n8n hit it with HTTP Request — since they’re on the same docker-compose network n8n can reach it by service name, way cleaner than trying to mount the docker socket

add like 5 lines of Flask to your python container (from flask import Flask; app.route('/run') that calls your script), update the email creds and shared volume path and you’re set

Yeah, thanks. From what I’ve seen, that seems like the most efficient approach. I was considering the architecture I described above, but since my workflow only runs once a week, I figured that keeping a Python container running all the time with an API inside might be overkill. What am I missing?

@handsome_programmer for once a week you don’t need Flask running 24/7 — just mount the docker socket into your n8n container (/var/run/docker.sock:/var/run/docker.sock in your compose file) and then Execute Command can run docker start python-container directly. the socket gives n8n’s container access to the host docker daemon so it can spin up sibling containers on demand, no always-on API needed.

Thanks :folded_hands:

So I understand the Docker socket is enough to access the host Docker daemon.

But in my case the n8n image is very minimal and doesn’t include the docker CLI, so Execute Command can’t run docker start.

Do I need to extend the n8n image to add Docker CLI, or is there a better approach?

welcome to the n8n community @handsome_programmer
I’d only extend the n8n image with Docker CLI if you’re comfortable with n8n having Docker daemon access. Mounting the Docker socket is powerful but high-trust, so I’d avoid exposing this workflow to untrusted inputs and restrict who can edit/run it. A safer pattern is to keep the container-start logic outside n8n, for example in a small controlled runner or scheduler, and let n8n trigger that instead.

Thank you but are you sure the latest image is based on Alpine? I tried your exact code and it failed with a apk: not found error

=> ERROR [2/2] RUN apk add --no-cache docker-cli
------
 > [2/2] RUN apk add --no-cache docker-cli:
0.305 /bin/sh: apk: not found
------
Dockerfile:3
ERROR: failed to build: failed to solve: process "/bin/sh -c apk add --no-cache docker-cli" did not complete successfully: exit code: 127


Debian apt is not working either

You can try this

FROM n8nio/n8n:latest
USER root

# Restore apk from Alpine (n8n uses Alpine 3.22)
COPY --from=alpine:3.22 /sbin/apk /sbin/apk
COPY --from=alpine:3.22 /lib/apk /lib/apk
COPY --from=alpine:3.22 /etc/apk /etc/apk

RUN apk add --no-cache docker-cli
USER node