Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Running arbitrary node.js code in a docker?

Featured Replies

Greetings all.  Between various home automation scripts and some web things, I keep encountering the need to run various node.js code, usually as "glue" for this and that.  It's pretty rare than anyone bothers to put together a docker for this stuff, let alone something that runs out of the box in unraid.

 

I've spent some time going down the rabbit hole trying to build something myself, but I seem to keep getting hung up on getting the actual code into the docker in quite the same way as other packaged dockers I've run.

 

Does anyone have any pointers or, ideally, any specific method they've used to do this in the past.  Basically, I need to bring in a node.js docker, import some arbitrary code (ideally I'd like this code to live in the appdata share so I can modify it without updating the docker), and be able to run that code on the docker launch.

 

Any thoughts?  Thanks! 

On 7/19/2019 at 9:54 AM, peng1can said:

Greetings all.  Between various home automation scripts and some web things, I keep encountering the need to run various node.js code, usually as "glue" for this and that.  It's pretty rare than anyone bothers to put together a docker for this stuff, let alone something that runs out of the box in unraid. 

 

I've spent some time going down the rabbit hole trying to build something myself, but I seem to keep getting hung up on getting the actual code into the docker in quite the same way as other packaged dockers I've run.

  

Does anyone have any pointers or, ideally, any specific method they've used to do this in the past.  Basically, I need to bring in a node.js docker, import some arbitrary code (ideally I'd like this code to live in the appdata share so I can modify it without updating the docker), and be able to run that code on the docker launch.

 

Any thoughts?  Thanks! 

Hi @peng1can

I'm not saying this is the very best way, but this is what I'd do...

Create the folder (in appdata if you'd like) with your node.js code files inside it

run a node.js container that executes your code:

docker run -d --rm -v /mnt/user/appdata/my_nodejs:/my_nodejs node:lts-alpine node /my_nodejs/peng1can.js

change "my_nodejs" to the folder name you made, change "pen1can.js" do your node js file you need to execute

 

Very simple example but it can be expanded depending on what you're doing with node.

Edited by dee31797

That is how I would (and do) do it as well.

  • Author

Thanks!  I'll give this a try.

Another thing you could think about is using Node-Red instead of just a node.js script. I've found I could put the vast majority of my home automation related node.js scripts in Node-Red. For me that is easier to support than a random js script running somewhere, but your needs may differ.

  • 6 months later...

Will npm install get run automatically somehow if you put package.json there too?  Will you be able to then control this container from the unraid gui?

I made a dir for my little node app called "wx":

cd /mnt/user/appdata; mkdir wx; cd wx

 

Then I made a simple Dockerfile with the following contents:

FROM node:6.8.1

WORKDIR /usr/src/app

COPY package.json .

RUN npm install

COPY server.js .

EXPOSE 3006
CMD [ "node", "server.js" ]

 

Then I created the docker image:

docker build -t foo/wx .

 

Then I started it with:

docker run --net=nginx -h wx --name wx -p 3006:3006 -d foo/wx

 

nginx is the net I created following the spaceinvaderone letsencrypt/nginx video.

 

After starting this container it shows up in the docker tab in unraid but all you can really do is stop or remove it.

 

How can I autostart it?

Edited by uek2wooF
added "with the following contents"

  • 4 months later...
On 2/4/2020 at 9:08 PM, uek2wooF said:

I made a dir for my little node app called "wx":

cd /mnt/user/appdata; mkdir wx; cd wx

 

Then I made a simple Dockerfile with the following contents:

FROM node:6.8.1

WORKDIR /usr/src/app

COPY package.json .

RUN npm install

COPY server.js .

EXPOSE 3006
CMD [ "node", "server.js" ]

 

Then I created the docker image:

docker build -t foo/wx .

 

Then I started it with:

docker run --net=nginx -h wx --name wx -p 3006:3006 -d foo/wx

 

nginx is the net I created following the spaceinvaderone letsencrypt/nginx video.

 

After starting this container it shows up in the docker tab in unraid but all you can really do is stop or remove it.

 

How can I autostart it?

How did you solve your problem? Did you add something /boot/config/go to start your app automatically?

  • 2 weeks later...

I don't think I did anything other than just check "autostart".  It just starts.

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.