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:
Trigger a Python container execution
The Python script generates an Excel file into the shared volume
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
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.
for once-a-week that’s the right call — extend the n8n image to add docker-cli instead of running an always-on sidecar. since n8n’s base image is Alpine, a minimal Dockerfile does it:
FROM n8nio/n8n:latest
USER root
RUN apk add --no-cache docker-cli
USER node
combine that with the /var/run/docker.sock:/var/run/docker.sock volume mount achamm mentioned and Execute Command can run docker start python-container directly. the socket gives the CLI access to the host daemon — no extra service needed.
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.