Docker in Docker in Kubernetes

Describe the issue/error/question

I would like to run docker commands in a node. For example I would like to execute:

docker run hello-world

What is the error message (if any)?

There is no docker support in the n8n docker image, so I can’t run Docker images.

Please share the workflow

Share the output returned by the last node

NodeOperationError: Command failed: docker run hello-world
/bin/sh: docker: not found

    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/ExecuteCommand/ExecuteCommand.node.js:76:27)
    at async Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:658:28)
    at async /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:585:53

Information on your n8n setup

  • n8n version:
    image:
    repository: n8nio/n8n
    tag: “0.203.1”
  • Database you’re using (default: SQLite): PostgreSQL
  • Running n8n with the execution process [own(default), main]: default
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker in Kubernetes

So my idea is to setup a docker-in-docker (DinD) container in the same Kubernetes pod so the DinD provides the docker functionality. This is pretty much a standard Kubernetes DinD setup nowadays.

Having DinD would allow me to write my scripts using any programing language, pack them in a docker image then run them in a N8N node. I already use this approach in Jenkins, however I would like to use N8N because I think it is more user friendly.

Just wondering if this has been attempted before.

Hi @Spritekin, welcome to the community!

docker is not available as a command in the n8n standard docker image, but you could create a custom image based on your specific requirements. The n8n repo contains an example Dockerfile here.

Alternatively, perhaps you might want to consider using the ssh node to connect to any other container or host that has access to docker? This would allow you to stick with the default n8n image.