Shutting Down a Windows PC from Node-RED Running in Docker – Best Practices & Deployment Advice

I am relatively new to Node-RED and have been learning through daily contributions over the past few months. I am now approaching the stage where I can build a partial project, as shown in the attached image.

Currently, I am exploring how to shut down a Windows PC from Node-RED. I am running Node-RED in Docker. I chose Docker to simplify deployment in production environments, avoiding the need to install multiple palettes or modify settings.js on several machines. The program is primarily a runtime HMI with some SCADA features and network connectivity.

Regarding PC shutdown, I have currently created a .bat file that safely closes Docker and its containers before shutting down the PC. However, since Docker is running on Linux, I may not be able to execute the .bat file directly.

I welcome any feedback on how to enhance this setup and make it more practical for future deployments. Additionally, I would like to know if installing Node-RED directly on Windows (rather than in Docker) would allow me to build a project and then easily move or replicate it on other machines, avoiding the need to configure each PC individually.

I would appreciate guidance or best practices for handling this scenario.

I believe a sigterm is send to the docker daemon automatically when shutting down windows, which should shutdown the containers gracefully (same applies to linux). To control docker remotely you should be able to control this via the daemon. - or use preshared ssh keys and remotely execute via an exec node.

But if you have a large number of systems that you want to control remotely, i think it may be more practical to use Ansible instead ?

No, you can't. Docker is effectively a separate system and so you would need both admin rights and remote command ability on the host from whatever account is running Node-RED on the guest. Modern Windows supports OpenSSH so that might be one way. You should also consider using a .ps1 PowerShell script rather than a legacy cmd batch file.

Replicating a Node-RED instance to another computer is pretty straight-forwards. As long as the other computers run the same OS, you could do a straight sync copy. Just note that a typical node-red install may have thousands of small files which can be time consuming to copy. You could have a script to zip everything up and then copy and unpack on the other end. Or you could exclude the node_modules folder from the copy and run a manual npm install on the other end. If you are copying from Windows to Linux or Mac, or if the other end has a different major version of node.js, you will have to do at least an npm rebuild anyway.

You should also give some thought as to how you want to manage both node.js and node-red itself on all of your computers. Both will need regular maintenance.

As bakman2 advises, if you have a significant number of computers to manage, something like Ansible, or maybe Intune if you have the Azure infrastructure available would be advisable and in exchange for the pain of initial setup, you will get far simpler and more robust ongoing management.