Install npm packages in Dockerfile after 1.x upgrade

Describe the problem/error/question

Before 1.x, in a docker compose deployment, all you had to do to install npm packages was to add the following lines to Dockerfile:

FROM n8nio/n8n

RUN npm install -g jsdom

However, from 1.x, docker runs using node user instead of root and this approach doesn’t work anymore due to permission errors.

There’s a suggested solution for this problem in this post: How to build own image with custom node modules? - #4 by MutedJam, which is to add USER root in the Dockerfile to be able to install the npm packages.

It works, however, it initiates n8n as a clean install and I’m not able to access my workflows anymore. Plus, it makes the install more insecure now that is running as root again.

There’s another solution given in this post: Problem for Adding packages to a docker install - #2 by MutedJam which is to add RUN cd /usr/local/lib/node_modules/n8n && npm install json to Dockerfile. However, this approach doesn’t work as well in the newest versions.

Can you provide a working way of installing npm packages for Docker compose runs that still relies on not running as root?

Information on your n8n setup

  • n8n version: 1.8.2
  • Database (default: SQLite): sqlite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): hetzner, docker compose
  • Operating system: Ubuntu

Hi @lfcipriani, I am sorry for the trouble.

Perhaps @netroy can advise on what the “proper” approach to installing custom npm packages is after the recent changes to our Docker images?

This should work in your case:


FROM n8nio/n8n

USER root

RUN npm install -g jsdom

USER node

@shrey-42 This solution worked! Thanks for your help!

1 Like

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