# Installing npm packages / nodes via Dockerfile

**URL:** https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466
**Category:** General
**Tags:** docker
**Created:** [25 November 2024 23:12 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466 "2024-11-25T23:12:14Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![erxncxte](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@erxncxte](https://discourse.nodered.org/u/erxncxte)
#### Post date: [25 November 2024 23:12 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466/1 "2024-11-25T23:12:14Z")

</div>

Hi, according to the Node Red Docker Github, you can add extra nodes via a Dockerfile.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd7a401f0feb9f4e5babffb482883ce4496d30a9.png)  
However, I am unable to get this to work with the same Dockerfile. Any pointers or ideas why this wouldn't be the case?  
I am running Docker on WSL / Ubuntu for context.

---

<div class="post-metadata">

### Author: ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)
#### Post date: [25 November 2024 23:17 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466/2 "2024-11-25T23:17:17Z")

</div>

you need to login into your NR docker container with

```auto
sudo docker exec -it <mycontainer> bash

```

than you can execute the npm command and add other packages

---

<div class="post-metadata">

### Author: ![erxncxte](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@erxncxte](https://discourse.nodered.org/u/erxncxte)
#### Post date: [25 November 2024 23:20 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466/3 "2024-11-25T23:20:09Z")

</div>

Thanks for your prompt reply. I have got packages installed this way, however I wish to deploy this container to many different devices with minimal manual input (for a commercial application), so I was hoping to streamline this process and have the Dockerfile control all of the package installations.

---

<div class="post-metadata">

### Author: ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)
#### Post date: [25 November 2024 23:25 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466/4 "2024-11-25T23:25:13Z")

</div>

you can [backup/zip](https://dockerlabs.collabnix.com/beginners/saving-images-as-tar/) an entire docker container and deploy to other systems easily ... but this docker specific and not related to NR .. so you will not find much help here 😉

---

<div class="post-metadata">

### Author: ![erxncxte](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@erxncxte](https://discourse.nodered.org/u/erxncxte)
#### Post date: [25 November 2024 23:30 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466/5 "2024-11-25T23:30:52Z")

</div>

I understand, my frustration moreso lies in that the [Node Red Docker documentation](https://github.com/node-red/node-red-docker) does not work as expected and I would like to know if it's a 'me problem' or a NR Image / Permissions issue. I would prefer to avoid zipped containers for distribution

---

<div class="post-metadata">

### Author: ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)
#### Post date: [25 November 2024 23:50 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466/6 "2024-11-25T23:50:03Z")

</div>

I don't think you will be able to provide additional NPM packages as part of the docker-compose file as they need to be installed after the NR docker instance is running

---

<div class="post-metadata">

### Author: ![erxncxte](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@erxncxte](https://discourse.nodered.org/u/erxncxte)
#### Post date: [26 November 2024 00:06 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466/7 "2024-11-26T00:06:05Z")

</div>

I am not trying to provide additional NPM packages as part of the docker-compose file. I am trying to provide them as part of the Dockerfile, as per the screenshot from the documentation provided by NR. If the instance needs to be running to install additional NPM packages, they should update these instructions accordingly. Pretty sure that defeats the whole purpose of containerization. Right?

---

<div class="post-metadata">

### Author: ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)
#### Post date: [26 November 2024 00:31 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466/8 "2024-11-26T00:31:22Z")

</div>

I have seen several discussion here in the forum on how to handle/install local NPM packages, but as per my understanding the NPM packages will always be downloaded for install. I don't think it will work offline or in local mode.

But there are others here with more on this topic 😉 sorry cant help futher

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [26 November 2024 07:26 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466/9 "2024-11-26T07:26:29Z")

</div>

> [@erxncxte](#):
>
> I am unable to get this to work with the same Dockerfile.

What happens exactly ?

You could instead add the packages to package.json, under the dependencies property and rebuild.

@xx_Nexus_xx

> you need to login into your NR docker container with

The concept of a docker container is that they should be considered immutable and are disposable.  
Once you update the container, the package is gone. Adding stuff to the container this way is a big no-no and completely missing the point.

---

<div class="post-metadata">

### Author: ![ThingsTinkerer](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@ThingsTinkerer](https://discourse.nodered.org/u/ThingsTinkerer)
#### Post date: [26 November 2024 08:59 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466/10 "2024-11-26T08:59:01Z")

</div>

Sorry I had to re-edit this entire post because I forgot to check my own setup.

Turns out I needed to specifically add package.json to the image in the Dockerfile:

`COPY package.json .`

This is done in "Stage BASE" after WORKDIR is set.

What I do is add any packages on host, either through npm or palette or whatever. This will update package.json. After that, I can build the image, copying the package.json from the mount/project folder into the image.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [24 February 2025 08:59 UTC](https://discourse.nodered.org/t/installing-npm-packages-nodes-via-dockerfile/93466/11 "2025-02-24T08:59:03Z")

</div>

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