Install n8n community node in Docker

Background context

I am trying to build a Docker image of n8n with Python supported (in order to work with external libraries) and Python Function node (community node for Python coding in n8n) natively installed.

Following the instruction to build a custom image of n8n, I modified the official Dockerfile for n8n-custom. Furthermore, by the instruction from official page for adding n8n-nodes-python to n8n instance, I also added the line RUN cd /usr/local/lib/node_modules/n8n && npm install n8n-nodes-python to the Dockerfile. Below is my final Docker file:

ARG NODE_VERSION=20
# 1. Create an image to build n8n
FROM --platform=linux/arm64 n8nio/base:${NODE_VERSION} AS builder

# Build the application from source
WORKDIR /src
COPY . /src

# Install dependencies and build the project
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store --mount=type=cache,id=pnpm-metadata,target=/root/.cache/pnpm/metadata DOCKER_BUILD=true pnpm install --frozen-lockfile
RUN pnpm build

# Delete all dev dependencies
RUN jq 'del(.pnpm.patchedDependencies)' package.json > package.json.tmp; mv package.json.tmp package.json
RUN node .github/scripts/trim-fe-packageJson.js

# Delete any source code, source-mapping, or typings
RUN find . -type f -name "*.ts" -o -name "*.js.map" -o -name "*.vue" -o -name "tsconfig.json" -o -name "*.tsbuildinfo" | xargs rm -rf

# Deploy the `n8n` package into /compiled
RUN mkdir /compiled
RUN NODE_ENV=production DOCKER_BUILD=true pnpm --filter=n8n --prod --no-optional deploy /compiled

# 2. Start with a new clean image with just the code that is needed to run n8n
FROM n8nio/base:${NODE_VERSION}
ENV NODE_ENV=production

ARG N8N_RELEASE_TYPE=dev
ENV N8N_RELEASE_TYPE=${N8N_RELEASE_TYPE}

# Install Python and pip
RUN apk update && \
    apk add --no-cache python3 py3-pip

# Create a virtual environment in the /home/node/ directory
RUN python3 -m venv /home/node/venv

WORKDIR /home/node

# Copy necessary files from the builder stage
COPY --from=builder /compiled /usr/local/lib/node_modules/n8n
COPY docker/images/n8n/docker-entrypoint.sh /
COPY requirements.txt /home/node/requirements.txt

# Install Python dependencies for the n8n-python node
RUN . /home/node/venv/bin/activate && \
    pip install --no-cache-dir -r /home/node/requirements.txt

# Install the n8n-nodes-python module
RUN cd /usr/local/lib/node_modules/n8n && npm install n8n-nodes-python

# Ensure that the virtual environment's Python and pip are used
ENV PATH="/home/node/venv/bin:$PATH"

# Setup the Task Runner Launcher
ARG TARGETPLATFORM
ARG LAUNCHER_VERSION=0.1.1
ENV N8N_RUNNERS_MODE=internal_launcher \
    N8N_RUNNERS_LAUNCHER_PATH=/usr/local/bin/task-runner-launcher
COPY docker/images/n8n/n8n-task-runners.json /etc/n8n-task-runners.json
# First, download, verify, then extract the launcher binary
# Second, chmod with 4555 to allow the use of setuid
# Third, create a new user and group to execute the Task Runners under
RUN \
	if [[ "$TARGETPLATFORM" = "linux/amd64" ]]; then export ARCH_NAME="x86_64"; \
	elif [[ "$TARGETPLATFORM" = "linux/arm64" ]]; then export ARCH_NAME="aarch64"; fi; \
	mkdir /launcher-temp && \
	cd /launcher-temp && \
	wget https://github.com/n8n-io/task-runner-launcher/releases/download/${LAUNCHER_VERSION}/task-runner-launcher-$ARCH_NAME-unknown-linux-musl.zip && \
	wget https://github.com/n8n-io/task-runner-launcher/releases/download/${LAUNCHER_VERSION}/task-runner-launcher-$ARCH_NAME-unknown-linux-musl.sha256 && \
	sha256sum -c task-runner-launcher-$ARCH_NAME-unknown-linux-musl.sha256 && \
	unzip -d $(dirname ${N8N_RUNNERS_LAUNCHER_PATH}) task-runner-launcher-$ARCH_NAME-unknown-linux-musl.zip task-runner-launcher && \
	cd - && \
	rm -r /launcher-temp && \
	chmod 4555 ${N8N_RUNNERS_LAUNCHER_PATH} && \
	addgroup -g 2000 task-runner && \
	adduser -D -u 2000 -g "Task Runner User" -G task-runner task-runner

RUN \
	cd /usr/local/lib/node_modules/n8n && \
	npm rebuild sqlite3 && \
	cd - && \
	ln -s /usr/local/lib/node_modules/n8n/bin/n8n /usr/local/bin/n8n && \
	mkdir .n8n && \
	chown node:node .n8n

ENV SHELL /bin/sh
USER node
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]

The error message

When I build n8n image, I got the following message:

=> ERROR [stage-1  9/12] RUN cd /usr/local/lib/node_modules/n8n && npm install n8n-nodes-python    10.8s
------
 > [stage-1  9/12] RUN cd /usr/local/lib/node_modules/n8n && npm install n8n-nodes-python:
10.73 npm ERR! code EUNSUPPORTEDPROTOCOL
10.74 npm ERR! Unsupported URL Type "workspace:": workspace:*
10.74
10.74 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-12-13T12_15_34_886Z-debug-0.log
------
Dockerfile:50
--------------------
  48 |
  49 |     # Install the n8n-nodes-python module
  50 | >>> RUN cd /usr/local/lib/node_modules/n8n && npm install n8n-nodes-python
  51 |
  52 |     # Ensure that the virtual environment's Python and pip are used
--------------------
ERROR: failed to solve: process "/bin/sh -c cd /usr/local/lib/node_modules/n8n && npm install n8n-nodes-python" did not complete successfully: exit code: 1

When I remove the line RUN cd /usr/local/lib/node_modules/n8n && npm install n8n-nodes-python', everything else work without any problem. I think the error is about the issue with dependencies, because npm doesn’t work with workspace:*.

My question

What should I do to solve this problem?

Information on your n8n setup

  • n8n version: 1.66.0
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Window

Hi @trinq

the workspace protocol is something used with pnpm and it looks like the n8n-nodes-python package was designed for pnpm. Try installing it with pnpm instead

RUN cd /usr/local/lib/node_modules/n8n && pnpm install n8n-nodes-python

1 Like

Thank you for you answer. Actually when I tried to build the Docker image with RUN cd /usr/local/lib/node_modules/n8n && pnpm install n8n-nodes-python, I got the following error message:

=> ERROR [stage-1  9/12] RUN cd /usr/local/lib/node_modules/n8n && pnpm install n8n-nodes-python                                                                                                                                                                                                                                   9.5s 
------
 > [stage-1  9/12] RUN cd /usr/local/lib/node_modules/n8n && pnpm install n8n-nodes-python:
1.366 ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-9.15.0.tgz
9.345  ERR_PNPM_CATALOG_ENTRY_NOT_FOUND_FOR_SPEC  No catalog entry '@types/express' was found for catalog 'default'.
------
Dockerfile:50
--------------------
  48 |
  49 |     # Install the n8n-nodes-python module
  50 | >>> RUN cd /usr/local/lib/node_modules/n8n && pnpm install n8n-nodes-python
  51 |
  52 |     # Ensure that the virtual environment's Python and pip are used
--------------------
ERROR: failed to solve: process "/bin/sh -c cd /usr/local/lib/node_modules/n8n && pnpm install n8n-nodes-python" did not complete successfully: exit code: 1

That’s something you’d probably have to reach out for to the package maintainer as it seems to have to do with dependency resolution in their registry.
Given that this package hasn’t been updated in 3 years, the error wouldn’t surprise me :grimacing:

1 Like

Hi everyone, when I come back to this problem, I came up with an idea to store all the data in n8n container and convert it to image. I first have a standard docker container, and install the PythonFunction node and others (if needed) within the container. Finally, I use docker commit to convert the container to an image, ensuring that all stages, including the volume data, were included.

While this approach may not be a formal solution, it has proven effective for my needs.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.