You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Periodically, the source code is recompiled and pushed to [nodered/node-red](https://hub.docker.com/r/nodered/node-red/tags?page=1&ordering=last_updated) on *DockerHub*. There's a lot of stuff at that page but it boils down to variations on two basic themes:
45
45
@@ -53,7 +53,7 @@ The suffixes refer to the version of "Node.js" installed when the image was buil
53
53
54
54
As you will see a bit further down, the current default for IOTstack is an image tag of `latest-12` which means Node-RED 2.x.x with Node.js version 12.
55
55
56
-
### IOTstack menu
56
+
### <aname="iotstackMenu"></a>IOTstack menu
57
57
58
58
When you select Node-RED in the IOTstack menu, the *template service definition* is copied into the *Compose* file.
59
59
@@ -64,11 +64,11 @@ You choose add-on nodes from a supplementary menu. We recommend accepting the de
64
64
Key points:
65
65
66
66
* Under new menu, you must press the right arrow to access the supplementary menu. Under old menu, the list of add-on nodes is displayed automatically.
67
-
* Do not be concerned if you can't find an add-on node you need in the list. You can also add nodes via Manage Palette once Node-RED is running. See [adding extra nodes](#adding-extra-nodes).
67
+
* Do not be concerned if you can't find an add-on node you need in the list. You can also add nodes via Manage Palette once Node-RED is running. See [adding extra nodes](#addNodes).
68
68
69
69
Choosing add-on nodes in the menu causes the *Dockerfile* to be created.
70
70
71
-
### IOTstack first run
71
+
### <aname="iotstackFirstRun"></a>IOTstack first run
72
72
73
73
On a first install of IOTstack, you are told to do this:
74
74
@@ -135,9 +135,9 @@ You should not remove the *base* image, even though it appears to be unused.
135
135
136
136
> Whether you see one or two rows depends on the version of `docker-compose` you are using and how your version of `docker-compose` builds local images.
137
137
138
-
## Securing Node-RED
138
+
## <aname="securingNodeRed"></a>Securing Node-RED
139
139
140
-
### Setting an encryption key for your credentials
140
+
### <aname="encryptionKey"></a>Setting an encryption key for your credentials
141
141
142
142
After you install Node-RED, you should set an encryption key. Completing this step will silence the warning you will see when you run:
143
143
@@ -192,7 +192,7 @@ $ cd ~/IOTstack
192
192
$ docker-compose restart nodered
193
193
```
194
194
195
-
### Setting a username and password for Node-RED
195
+
### <aname="credentials"></a>Setting a username and password for Node-RED
196
196
197
197
To secure Node-RED you need a password hash. Run the following command, replacing `PASSWORD` with your own password:
Copy that text to your clipboard, then follow the instructions at [Node-RED User Guide - Securing Node-RED - Username & Password-based authentication](https://nodered.org/docs/user-guide/runtime/securing-node-red#usernamepassword-based-authentication).
210
210
211
-
## Referring to other containers
211
+
## <aname="containerNames"></a>Referring to other containers
212
212
213
213
Node-RED can run in two modes. By default, it runs in "non-host mode" but you can also move the container to "host mode" by editing the Node-RED service definition in your *Compose* file to:
214
214
@@ -220,7 +220,7 @@ Node-RED can run in two modes. By default, it runs in "non-host mode" but you ca
220
220
221
221
2. Remove the `ports` directive and the mapping of port 1880.
222
222
223
-
### When Node-RED is not in host mode
223
+
### <aname="nonHostMode"></a>When Node-RED is not in host mode
224
224
225
225
Most examples on the web assume Node-RED and other services in the MING (Mosquitto, InfluxDB, Node-RED, Grafana) stack have been installed natively, rather than in Docker containers. Those examples typically include the loopback address + port syntax, like this:
226
226
@@ -244,7 +244,7 @@ influxdb:8086
244
244
245
245
Behind the scenes, Docker maintains a table similar to an `/etc/hosts` file mapping container names to the IP addresses on the internal bridged network that are assigned, dynamically, by Docker when it spins up each container.
246
246
247
-
### When Node-RED is in host mode
247
+
### <aname="hostmode"></a>When Node-RED is in host mode
248
248
249
249
This is where you use loopback+port syntax, such as the following to communicate with Mosquitto:
250
250
@@ -254,7 +254,7 @@ This is where you use loopback+port syntax, such as the following to communicate
254
254
255
255
What actually occurs is that Docker is listening to external port 1883 on behalf of Mosquitto. It receives the packet and routes it (layer three) to the internal bridged network, performing network address translation (NAT) along the way to map the external port to the internal port. Then the packet is delivered to Mosquitto. The reverse happens when Mosquitto replies. It works but is less efficient than when all containers are in non-host mode.
256
256
257
-
## GPIO Access
257
+
## <aname="accessGPIO"></a>GPIO Access
258
258
259
259
To communicate with your Raspberry Pi's GPIO you need to do the following:
260
260
@@ -265,7 +265,7 @@ To communicate with your Raspberry Pi's GPIO you need to do the following:
2. Install the `node-red-node-pi-gpiod` node. See [Adding extra nodes](#adding-extra-nodes). It allows you to connect to multiple Pis from the same Node-RED service.
268
+
2. Install the `node-red-node-pi-gpiod` node. See [Adding extra nodes](#addNodes). It allows you to connect to multiple Pis from the same Node-RED service.
269
269
3. Make sure that the `pigpdiod` daemon is running. The recommended method is listed [here](https://github.com/node-red/node-red-nodes/tree/master/hardware/pigpiod). In essence, you need to:
270
270
271
271
- Use `sudo` to edit `/etc/rc.local`;
@@ -281,7 +281,7 @@ To communicate with your Raspberry Pi's GPIO you need to do the following:
281
281
282
282
4. Drag a gpio node onto the canvas and configure it using the IP address of your Raspberry Pi (eg 192.168.1.123). Don't try to use 127.0.0.1 because that is the loopback address of the Node-RED container.
283
283
284
-
## Sharing files between Node-RED and the Raspberry Pi
284
+
## <aname="fileSharing"></a>Sharing files between Node-RED and the Raspberry Pi
285
285
286
286
Containers run in a sandboxed environment. A process running inside a container can't see the Raspberry Pi's file system. Neither can a process running outside a container access files inside the container.
287
287
@@ -372,7 +372,7 @@ Deploying the flow and clicking on the Inject node results in the debug message
372
372
373
373
You can reverse this process. Any file you place within the path `~/IOTstack/volumes/nodered/data` can be read by a "File in" node.
374
374
375
-
## Executing commands outside the Node-RED container
375
+
## <a name="sshOutside"></a>Executing commands outside the Node-RED container
376
376
377
377
A reasonably common requirement in a Node-RED flow is the ability to execute a command on the host system. The standard tool for this is an "exec" node.
378
378
@@ -400,7 +400,7 @@ The same thing will happen if a Node-RED "exec" node executes that `grep` comman
400
400
401
401
Docker doesn't provide any mechanism for a container to execute an arbitrary command **outside** of its container. A workaround is to utilise SSH. This remainder of this section explains how to set up the SSH scaffolding so that "exec" nodes running in a Node-RED container can invoke arbitrary commands **outside** container-space.
402
402
403
-
### Task Goal
403
+
### <a name="sshTaskGoal"></a>Task Goal
404
404
405
405
Be able to use a Node-RED `exec` node to perform the equivalent of:
406
406
@@ -413,14 +413,14 @@ where:
413
413
* `«HOSTNAME»` is any host under your control (not just the Raspberry Pi running IOTstack); and
414
414
* `«COMMAND»` is any command known to the target host.
415
415
416
-
### Assumptions
416
+
### <a name="sshAssumptions"></a>Assumptions
417
417
418
418
* [SensorsIot/IOTstack](https://github.com/SensorsIot/IOTstack) is installed on your Raspberry Pi.
419
419
* The Node-RED container is running.
420
420
421
421
These instructions are specific to IOTstack but the underlying concepts should apply to any installation of Node-RED in a Docker container.
422
422
423
-
### Executing commands "inside" a container
423
+
### <a name="dockerExec"></a>Executing commands "inside" a container
424
424
425
425
These instructions make frequent use of the ability to run commands "inside" the Node-RED container. For example, suppose you want to execute:
426
426
@@ -466,19 +466,19 @@ You have several options:
466
466
467
467
3. Run the command from Portainer by selecting the container, then clicking the ">_ console" link. This is identical to opening a shell.
You will need to have a few concepts clear in your mind before you can set up SSH successfully. I use double-angle quote marks (guillemets) to mean "substitute the appropriate value here".
The name of your Raspberry Pi. When you first booted your RPi, it had the name "raspberrypi" but you probably changed it using `raspi-config`. Example:
Create a key-pair for Node-RED. This is done by executing the `ssh-keygen` command **inside** the container:
521
521
@@ -531,7 +531,7 @@ Notes:
531
531
* press "y" to overwrite (and lose the old keys)
532
532
* press "n" to terminate the command, after which you can investigate why a key-pair already exists.
533
533
534
-
### <a name="sshStep2">Step 2: *Exchange keys with target hosts* (once per target host)</a>
534
+
### <a name="sshStep2"></a>Step 2: *Exchange keys with target hosts* (once per target host)
535
535
536
536
Node-RED's public key needs to be copied to the user account on *each* target machine where you want a Node-RED "exec" node to be able to execute commands. At the same time, the Node-RED container needs to learn the public host key of the target machine. The `ssh-copy-id` command does both steps. The required syntax is:
537
537
@@ -581,7 +581,7 @@ and check to make sure that only the key(s) you wanted were added.
581
581
582
582
If you do not see an indication that a key has been added, you may need to retrace your steps.
583
583
584
-
### Step 3: *Perform the recommended test*
584
+
### <a name="sshStep3"></a>Step 3: *Perform the recommended test*
585
585
586
586
The output above recommends a test. The test needs to be run **inside** the Node-RED container so the syntax is:
587
587
@@ -602,9 +602,9 @@ If everything works as expected, you should see a list of the files in your IOTs
602
602
603
603
Assuming success, think about what just happened? You told SSH **inside** the Node-RED container to run the `ls` command **outside** the container on your Raspberry Pi. You broke through the containerisation.
604
604
605
-
### Understanding what's where and what each file does
605
+
### <a name="sshWhatsWhere"></a>Understanding what's where and what each file does
606
606
607
-
#### What files are where
607
+
#### <a name="sshFileLocations"></a>What files are where
608
608
609
609
Six files are relevant to Node-RED's ability to execute commands outside of container-space:
610
610
@@ -617,7 +617,7 @@ Six files are relevant to Node-RED's ability to execute commands outside of cont
617
617
618
618
Unless you take precautions, those keys will change whenever your Raspberry Pi is rebuilt from scratch and that **will** stop SSH from working.
619
619
620
-
You can recover by re-running [`ssh-copy-id`](#step-2-exchange-keys-with-target-hosts-once-per-target-host).
620
+
You can recover by re-running [`ssh-copy-id`](#sshStep2).
621
621
622
622
* in `~/IOTstack/volumes/nodered/ssh`:
623
623
@@ -632,7 +632,7 @@ Six files are relevant to Node-RED's ability to execute commands outside of cont
632
632
633
633
If you lose or destroy these keys, SSH **will** stop working.
634
634
635
-
You can recover by [generating new keys](#step-1-generate-ssh-key-pair-for-node-red-one-time) and then re-running [`ssh-copy-id`](#sshStep2).
635
+
You can recover by [generating new keys](#sshStep1) and then re-running [`ssh-copy-id`](#sshStep2).
636
636
637
637
- `known_hosts`
638
638
@@ -654,7 +654,7 @@ Six files are relevant to Node-RED's ability to execute commands outside of cont
654
654
655
655
Note that providing the correct password at the command line will auto-repair the `authorized_keys` file.
656
656
657
-
#### What each file does
657
+
#### <a name="sshFilePurpose"></a>What each file does
658
658
659
659
SSH running **inside** the Node-RED container uses the Node-RED container's private key to provide assurance to SSH running **outside** the container that it (the Node-RED container) is who it claims to be.
The first line is the result of running the command inside the Node-RED container. The second line is the result of running the same command outside the Node-RED container on the Raspberry Pi.
807
807
808
-
### Suppose you want to add another «HOSTNAME»
808
+
### <a name="addHostname"></a>Suppose you want to add another «HOSTNAME»
809
809
810
810
1. Exchange keys with the new target host using:
811
811
@@ -821,7 +821,7 @@ In the Node-RED GUI:
821
821
822
822
to define the new host. Remember to use `sudo` to edit the file. There is no need to restart Node-RED or recreate the container.
@@ -863,7 +863,7 @@ Your existing Node-RED container continues to run while the rebuild proceeds. On
863
863
The `prune` is the simplest way of cleaning up old images. Sometimes you need to run this twice, the first time to clean up the old local image, the second time for the old base image. Whether an old base image exists depends on the version of `docker-compose` you are using and how your version of `docker-compose` builds local images.
You customise your *local* image of Node-RED by making changes to:
869
869
@@ -881,7 +881,7 @@ $ docker system prune
881
881
882
882
The `--build` option on the `up` command (as distinct from a `docker-compose build` command) works in this situation because you've made a substantive change to your *Dockerfile*.
883
883
884
-
### Node.js version
884
+
### <a name="nodeJSversion"></a>Node.js version
885
885
886
886
Out of the box, IOTstack starts the Node-RED *Dockerfile* with:
887
887
@@ -903,9 +903,9 @@ In the unlikely event that you need to run an add-on node that needs version 10
903
903
FROM nodered/node-red:latest-10
904
904
```
905
905
906
-
Once you have made that change, follow the steps at [apply *Dockerfile* changes](#upgrading-node-red).
906
+
Once you have made that change, follow the steps at [apply *Dockerfile* changes](#applyDockerfileChange).
907
907
908
-
### Adding extra packages
908
+
### <a name="addPackage"></a>Adding extra packages
909
909
910
910
As well as providing the Node-RED service, the nodered container is an excellent testbed. Installing the DNS tools, Mosquitto clients and tcpdump will help you to figure out what is going on **inside** container-space.
You can add as many extra packages as you like. They will persist until you change the *Dockerfile* again.
929
929
930
-
Once you have made this change, follow the steps at [apply *Dockerfile* changes](#upgrading-node-red).
930
+
Once you have made this change, follow the steps at [apply *Dockerfile* changes](#applyDockerfileChange).
931
931
932
-
### Adding extra nodes
932
+
### <a name="addNodes"></a>Adding extra nodes
933
933
934
934
You can install nodes by:
935
935
936
-
1. Adding nodes to the *Dockerfile* and then following the steps at [apply *Dockerfile* changes](#upgrading-node-red).
936
+
1. Adding nodes to the *Dockerfile* and then following the steps at [apply *Dockerfile* changes](#applyDockerfileChange).
937
937
938
938
This is also what will happen if you re-run the menu and change the selected nodes, except that the menu will also blow away any other customisations you may have made to your *Dockerfile*.
939
939
@@ -997,7 +997,7 @@ If you're wondering about "backup", nodes installed via:
997
997
998
998
Basically, if you're running IOTstack backups then your add-on nodes will be backed-up.
999
999
1000
-
### Node precedence
1000
+
### <a name="nodePrecedence"></a>Node precedence
1001
1001
1002
1002
Add-on nodes that are installed via *Dockerfile* wind up at the **internal** path:
1003
1003
@@ -1037,7 +1037,7 @@ take precedence over those installed at:
1037
1037
1038
1038
Or, to put it more simply: in any contest, Manage Palette prevails over *Dockerfile*.
Sometimes, even when you are 100% certain that **you** didn't do it, an add-on node will turn up in both places. There is probably some logical reason for this but I don't know what it is.
0 commit comments