peng1can Posted July 19, 2019 Share Posted July 19, 2019 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! Quote Link to comment
dee31797 Posted July 21, 2019 Share Posted July 21, 2019 (edited) 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 July 21, 2019 by dee31797 Quote Link to comment
JasonJoel Posted July 22, 2019 Share Posted July 22, 2019 That is how I would (and do) do it as well. Quote Link to comment
peng1can Posted July 22, 2019 Author Share Posted July 22, 2019 Thanks! I'll give this a try. Quote Link to comment
JasonJoel Posted July 23, 2019 Share Posted July 23, 2019 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. Quote Link to comment
uek2wooF Posted February 3, 2020 Share Posted February 3, 2020 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? Quote Link to comment
uek2wooF Posted February 4, 2020 Share Posted February 4, 2020 (edited) 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 February 4, 2020 by uek2wooF added "with the following contents" Quote Link to comment
-Pavel- Posted June 13, 2020 Share Posted June 13, 2020 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? Quote Link to comment
uek2wooF Posted June 23, 2020 Share Posted June 23, 2020 I don't think I did anything other than just check "autostart". It just starts. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.