Issues with getting n8n running in a Docker container with custom nodes

Describe the problem/error/question

I’ll start off by saying I am very very new to Docker and have avoided it up to this point, but it seems like I’m going to have to learn it haha. I’m trying to get an n8n instance running locally so that I can work with developing a few custom nodes but for whatever reason I’m having the hardest time getting it done. Firstly it seems to hang when starting n8n at this point:

Finished migration MoveSshKeysToDatabase1711390882123
Starting migration RemoveNodesAccess1712044305787
Finished migration RemoveNodesAccess1712044305787
Starting migration CreateProject1714133768519
Finished migration CreateProject1714133768519
Starting migration MakeExecutionStatusNonNullable1714133768521
Finished migration MakeExecutionStatusNonNullable1714133768521
Starting migration AddActivatedAtUserSetting1717498465931
Finished migration AddActivatedAtUserSetting1717498465931
Starting migration AddConstraintToExecutionMetadata1720101653148
Finished migration AddConstraintToExecutionMetadata1720101653148
Version: 1.53.0

Editor is now accessible via:
http://localhost:5678/

And when visiting it within my browser I get a refusal error. If I build that basic n8n Dockerfile it works no problem.

I’m using the Docker file specifically defined in the documentation to try and do the import of the custom node and it looks like this:

ARG NODE_VERSION=20
FROM n8nio/base:${NODE_VERSION}

ARG N8N_VERSION
RUN if [ -z "$N8N_VERSION" ] ; then echo "The N8N_VERSION argument is missing!" ; exit 1; fi

LABEL org.opencontainers.image.title="n8n"
LABEL org.opencontainers.image.description="Workflow Automation Tool"
LABEL org.opencontainers.image.source="https://github.com/n8n-io/n8n"
LABEL org.opencontainers.image.url="https://n8n.io"
LABEL org.opencontainers.image.version=${N8N_VERSION}

ENV N8N_VERSION=${N8N_VERSION}
ENV NODE_ENV=production
ENV N8N_RELEASE_TYPE=stable
RUN set -eux; \
	npm install -g --omit=dev n8n@${N8N_VERSION} --ignore-scripts && \
	npm rebuild --prefix=/usr/local/lib/node_modules/n8n sqlite3 && \
	rm -rf /usr/local/lib/node_modules/n8n/node_modules/@n8n/chat && \
	rm -rf /usr/local/lib/node_modules/n8n/node_modules/n8n-design-system && \
	rm -rf /usr/local/lib/node_modules/n8n/node_modules/n8n-editor-ui/node_modules && \
	find /usr/local/lib/node_modules/n8n -type f -name "*.ts" -o -name "*.js.map" -o -name "*.vue" | xargs rm -f && \
	rm -rf /root/.npm

COPY docker-entrypoint.sh /

RUN \
	mkdir .n8n && \
	chown node:node .n8n

COPY ./n8n-nodes-starter ~/.n8n/custom/
ENV SHELL /bin/sh
USER node
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]

I do the COPY at the very end of the file, I could be doing it in the wrong place, however, every time I view the running containers file system that custom folder just doesn’t exist at all.

Any assistance with this would be greatly appreciated as I overall enjoy the product lol.

Information on your n8n setup

  • n8n version: 1.52.2

  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker

  • Operating system: Windows 11

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:

Hey @Cypher,

Can you try using the below from inside your nodes source folder, This is what I have used previously which has worked.

FROM n8nio/n8n:next

USER root
RUN npm config set -g production false

RUN mkdir /working-dir
COPY . /working-dir
RUN cd /working-dir && npm install && npm run build && npm pack && \
	cd /usr/local/lib/node_modules/n8n && npm install /working-dir/*.tgz

RUN rm -rf /working-dir

RUN npm config set -g production true
USER node

Looking at it now maybe updating /usr/local/lib/nodoe_modules/n8n to /home/node/.n8n/custom might be needed as well.

Hey @Jon,

I tried to use the file you provided, however, I’m getting errors on it still. The first issue was with the following line:

RUN npm config set -g production false

I’m getting a deprecation error, so I updated the file to include --omit=dev in the npm install command.

However after doing that, the build gets to a point and fails with the following error:

 > [4/6] RUN cd /working-dir && npm install --omit=dev && npm run build && npm pack &&    cd /home/node/.n8n/custom && npm install /working-dir/*.tgz:
1.418
1.418 > [email protected] preinstall
1.418 > npx only-allow pnpm
1.418 
2.788 npm warn exec The following package was not found and will be installed: [email protected]
3.019 ╔═════════════════════════════════════════════════════════════╗
3.019 ║                                                             ║
3.019 ║   Use "pnpm install" for installation in this project.      ║
3.019 ║                                                             ║
3.019 ║   If you don't have pnpm, install it via "npm i -g pnpm".   ║
3.019 ║   For more details, go to https://pnpm.js.org/              ║
3.019 ║                                                             ║
3.019 ╚═════════════════════════════════════════════════════════════╝
3.030 npm ERR! code 1
3.030 npm ERR! path /working-dir
3.030 npm ERR! command failed
3.031 npm ERR! command sh -c npx only-allow pnpm
3.031
3.031 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-08-03T12_55_36_380Z-debug-0.log
------
Dockerfile:7
--------------------
   6 |     COPY . /working-dir
   7 | >>> RUN cd /working-dir && npm install --omit=dev && npm run build && npm pack && \
   8 | >>>      cd /home/node/.n8n/custom && npm install /working-dir/*.tgz       
   9 |
--------------------
ERROR: failed to solve: process "/bin/sh -c cd /working-dir && npm install --omit=dev && npm run build && npm pack && \tcd /home/node/.n8n/custom && npm install /working-dir/*.tgz" did not complete successfully: exit code: 1

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/oxg74y0plhm244jw05l6mp425

Sorry if I’m being vague, I’m in territory I’m not familar with haha.

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