Hosting custom node with docker

Problem

I have set up a custom node and I’m now trying to deploy into a docker container I have, but first I’m setting up locally to see if everything works just fine. Locally, via n8n start, using npm, everything works just fine and I’ve been able to develop my action nodes quite well for the past few months. But after replicating the folders and copying everything into my container, I’m
still not being able to find my node.
There aren’t any errors as I am able to build and run docker compose up with success and then access n8n on my browser.

Dockerfile


ARG N8N_VERSION=1.47.3

RUN apk add --no-cache python3 py3-pip \
    && apk add --no-cache graphicsmagick tzdata git tini su-exec \
    && apk add --update --virtual build-dependencies python3 build-base ca-certificates \
    && npm install -g full-icu n8n@$N8N_VERSION \
    && apk del build-dependencies \
    && rm -rf /root /tmp/* /var/cache/apk/* \
    && mkdir /root

ENV NODE_ICU_DATA /usr/local/lib/node_modules/full-icu

WORKDIR /home/.n8n/custom/n8n-node

EXPOSE 5678

COPY . .
WORKDIR /home/.n8n/custom/n8n-node/nodes/mynode
RUN npm link

WORKDIR /home/.n8n/custom/n8n-node
RUN npm link custom-n8n-node

RUN npm install \
    #&& npm i --dev [email protected] @types/[email protected] @types/[email protected] gulp @types/tmp @types/express n8n-workflow n8n-core gulp-typescript @types/jest \
    && npm run build

CMD ["n8n", "start"]```

FROM node:20-alpine

ARG N8N_VERSION=1.47.3

RUN apk add --no-cache python3 py3-pip \
    && apk add --no-cache graphicsmagick tzdata git tini su-exec \
    && apk add --update --virtual build-dependencies python3 build-base ca-certificates \
    && npm install -g full-icu n8n@$N8N_VERSION \
    && apk del build-dependencies \
    && rm -rf /root /tmp/* /var/cache/apk/* \
    && mkdir /root

ENV NODE_ICU_DATA /usr/local/lib/node_modules/full-icu

WORKDIR /home/.n8n/custom/unbabel-n8n-node

EXPOSE 5678

COPY . .

WORKDIR /home/.n8n/custom/unbabel-n8n-node/nodes/unbabel

# Create a local symlink for the custom node package
RUN npm link

WORKDIR /home/.n8n/custom/unbabel-n8n-node

RUN npm link n8n-nodes-unbabel

RUN npm install \
    #&& npm i --dev [email protected] @types/[email protected] @types/[email protected] gulp @types/tmp @types/express n8n-workflow n8n-core gulp-typescript @types/jest \
    && npm run build

CMD ["n8n", "start"]

docker-compose.yml

version: "3.9"

x-env: &environment
  environment: 
    N8N_TEMPLATES_ENABLED: "false"
    # Basic auth credentials
    N8N_ENCRYPTION_KEY: "s4p3rs3cr3t"
    GENERIC_TIMEZONE: "Europe/Lisbon"
    NODE_ENV: "development"
    # List of external modules
    NODE_FUNCTION_ALLOW_EXTERNAL: "axios,jwt-decode,tempy,tmp,dotenv,gulp,n8n,n8n-core,n8n-workflow"
    # Increase node max memory
    NODE_OPTIONS: "--max_old_space_size=1024"
    # Set n8n to work as single thread instead of forking to worker threads
    EXECUTIONS_PROCESS: "main"

services:
  app:
    <<: *environment
    build: .
    volumes:
      - .:/home/node/.n8n/custom
    ports:
      - "5678:5678"
    command: n8n start
  • n8n version: N8N 1.47.3 (same I am running locally)
  • Running Via - Docker compose on MACOS (M2)
  • I don’t have a DB

I’m thinking the problem is with where I’m copying the files into my image.

Any help would be appreciated. Thank you

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Hello @Tomas_Da_Mota ,

Thanks for sharing your issue with us here in the community.

I check your description and when you say you build and run you mean you are recreating your docker container, correct? I see some discussion on the past around it in How to add custom nodes on Docker Configuration - #4 by tight-crow-1218

Other discussion also in here Install n8n-nodes-module in custom n8n image - #8 by Dtneo

Let us know if the discussions added any insight you may have missed.

Cheers, Flavio

Hi,

Have you attempted to install your link package globally?
RUN npm install -g link

Here’s an example of my Dockerfile:

FROM n8nio/n8n:latest

WORKDIR /data
USER root

# Install Python and pip
RUN apk add --no-cache libzbar python3 py3-pip libmagic poppler-utils && \
    apk upgrade py3-pip
# Add your NodeJS packages here - make sure you install them globally (-g)
RUN npm install -g link

@CristianG
Hey, I’ve tried that but with no avail, could you share your full dockerfile please? That would clarify the situation better.
Thanks.

hey @Flavio_Orfano unfortunately those solutions won’t work. In my image I am copying the file into home/node/.n8n as you can see in my dockerfile, however it won’t show the node.

let me know if you have any other resources I could use.

This was my entire Dockerfile.

FROM n8nio/n8n:latest

WORKDIR /data
USER root

# Install Python and pip
RUN apk add --no-cache libzbar python3 py3-pip libmagic poppler-utils && \
    apk upgrade py3-pip
# Add your NodeJS packages here - make sure you install them globally (-g)
RUN npm install -g ldapjs zxcvbn [email protected] ip akamai-edgegrid xmlrpc

And here’s my docker-compose.yml:

version: "3"

services:
  n8n:
    image: n8n-python
    user: "node"
    restart: unless-stopped
    ports:
      - "0.0.0.0:443:5678"
    environment:
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_SSL_CERT=/etc/.n8n/certs/server.crt
      - N8N_SSL_KEY=/etc/.n8n/certs/server.key
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - NODE_FUNCTION_ALLOW_EXTERNAL=ldapjs,zxcvbn,crypto,ip-cidr,ip,akamai-edgegrid,xmlrpc
      - N8N_AUTH_EXCLUDE_ENDPOINTS=api
    volumes:
      - ${DATA_FOLDER}/.n8n:/home/node/.n8n
      - ${DATA_FOLDER}/local-files:/files
      - ./custom:/home/node/.n8n/custom
      - ./python_scripts:/data/py_scripts
      - ./requirements.txt:/data/requirements.txt
      - ./certs:/etc/.n8n/certs

And then I’m building this image with:
docker build -t n8n-python .

Just a clarification: the npm packages installed with RUN npm install won’t appear in n8n as nodes, but you can use them in your code nodes.
For instance, here’s how I use the ldapjs package in a code node:

const ldap = require('ldapjs');
const client = ldap.createClient({
  url: 'your_ldap_server'
});
rest of your code here

EDIT:
Oh, sorry, I might have read your question wrong. You’re asking about a custom node that you developed.
For that, I would ensure that the generated files (from your dist folder) are copied into the correct locations and that you’ve updated the package.json file to include your node and credential files.

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