Skip to content

Commit 3c74bba

Browse files
committed
20220324 Node-RED docs - master branch
Fixes internal hyperlink problems discovered while discussing SensorsIot#521. Adds "stackoverflow" style anchors to each title. Tested by running through MacDown-to-HTML-to-BBEdit link checker. No broken links as of this commit. `mkdocs` still uses auto-generated anchors. Those will always work because they depend on the actual headings at the moment of generation. It is only internal cross-references that can fracture if too much reliance is place on auto-generated anchors plus an assumption that titles will either never change or that authors will be cognisant of the need to re-validate internal anchors BY HAND. Signed-off-by: Phill Kelley <[email protected]>
1 parent 9cc8533 commit 3c74bba

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

docs/Containers/Node-RED.md

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Node-RED
22

3-
## References
3+
## <a name=references></a>References
44

55
- [nodered.org home](https://nodered.org/)
66
- [GitHub: node-red/node-red-docker](https://github.com/node-red/node-red-docker)
77
- [DockerHub: nodered/node-red](https://hub.docker.com/r/nodered/node-red)
88
- [Tutorial: from MQTT to InfluxDB via Node-Red](https://gist.github.com/Paraphraser/c9db25d131dd4c09848ffb353b69038f)
99

10-
## Significant files
10+
## <a name="significant-files"></a>Significant files
1111

1212
```
1313
~/IOTstack
@@ -33,13 +33,13 @@
3333
6. Data directory (mapped volume).
3434
7. SSH directory (mapped volume).
3535

36-
## How Node-RED gets built for IOTstack
36+
## <a name="iotstackBuild"></a>How Node-RED gets built for IOTstack
3737

38-
### Node-RED source code ([GitHub](https://github.com))
38+
### <a name="gitHubSource"></a>Node-RED source code ([GitHub](https://github.com))
3939

4040
The source code for Node-RED lives at [GitHub node-red/node-red-docker](https://github.com/node-red/node-red-docker).
4141

42-
### Node-RED images ([DockerHub](https://hub.docker.com))
42+
### <a name="dockerHubImages"></a>Node-RED images ([DockerHub](https://hub.docker.com))
4343

4444
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:
4545

@@ -53,7 +53,7 @@ The suffixes refer to the version of "Node.js" installed when the image was buil
5353

5454
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.
5555

56-
### IOTstack menu
56+
### <a name="iotstackMenu"></a>IOTstack menu
5757

5858
When you select Node-RED in the IOTstack menu, the *template service definition* is copied into the *Compose* file.
5959

@@ -64,11 +64,11 @@ You choose add-on nodes from a supplementary menu. We recommend accepting the de
6464
Key points:
6565

6666
* 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).
6868

6969
Choosing add-on nodes in the menu causes the *Dockerfile* to be created.
7070

71-
### IOTstack first run
71+
### <a name="iotstackFirstRun"></a>IOTstack first run
7272

7373
On a first install of IOTstack, you are told to do this:
7474

@@ -135,9 +135,9 @@ You should not remove the *base* image, even though it appears to be unused.
135135

136136
> 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.
137137
138-
## Securing Node-RED
138+
## <a name="securingNodeRed"></a>Securing Node-RED
139139

140-
### Setting an encryption key for your credentials
140+
### <a name="encryptionKey"></a>Setting an encryption key for your credentials
141141

142142
After you install Node-RED, you should set an encryption key. Completing this step will silence the warning you will see when you run:
143143

@@ -192,7 +192,7 @@ $ cd ~/IOTstack
192192
$ docker-compose restart nodered
193193
```
194194

195-
### Setting a username and password for Node-RED
195+
### <a name="credentials"></a>Setting a username and password for Node-RED
196196

197197
To secure Node-RED you need a password hash. Run the following command, replacing `PASSWORD` with your own password:
198198

@@ -208,7 +208,7 @@ $2a$08$gTdx7SkckJVCw1U98o4r0O7b8P.gd5/LAPlZI6geg5LRg4AUKuDhS
208208

209209
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).
210210

211-
## Referring to other containers
211+
## <a name="containerNames"></a>Referring to other containers
212212

213213
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:
214214

@@ -220,7 +220,7 @@ Node-RED can run in two modes. By default, it runs in "non-host mode" but you ca
220220

221221
2. Remove the `ports` directive and the mapping of port 1880.
222222

223-
### When Node-RED is not in host mode
223+
### <a name="nonHostMode"></a>When Node-RED is not in host mode
224224

225225
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:
226226

@@ -244,7 +244,7 @@ influxdb:8086
244244

245245
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.
246246

247-
### When Node-RED is in host mode
247+
### <a name="hostmode"></a>When Node-RED is in host mode
248248

249249
This is where you use loopback+port syntax, such as the following to communicate with Mosquitto:
250250

@@ -254,7 +254,7 @@ This is where you use loopback+port syntax, such as the following to communicate
254254

255255
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.
256256

257-
## GPIO Access
257+
## <a name="accessGPIO"></a>GPIO Access
258258

259259
To communicate with your Raspberry Pi's GPIO you need to do the following:
260260

@@ -265,7 +265,7 @@ To communicate with your Raspberry Pi's GPIO you need to do the following:
265265
$ sudo apt install pigpio python-pigpio python3-pigpio
266266
```
267267

268-
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.
269269
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:
270270

271271
- 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:
281281

282282
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.
283283

284-
## Sharing files between Node-RED and the Raspberry Pi
284+
## <a name="fileSharing"></a>Sharing files between Node-RED and the Raspberry Pi
285285

286286
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.
287287

@@ -372,7 +372,7 @@ Deploying the flow and clicking on the Inject node results in the debug message
372372

373373
You can reverse this process. Any file you place within the path `~/IOTstack/volumes/nodered/data` can be read by a "File in" node.
374374

375-
## Executing commands outside the Node-RED container
375+
## <a name="sshOutside"></a>Executing commands outside the Node-RED container
376376

377377
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.
378378

@@ -400,7 +400,7 @@ The same thing will happen if a Node-RED "exec" node executes that `grep` comman
400400

401401
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.
402402

403-
### Task Goal
403+
### <a name="sshTaskGoal"></a>Task Goal
404404

405405
Be able to use a Node-RED `exec` node to perform the equivalent of:
406406

@@ -413,14 +413,14 @@ where:
413413
* `«HOSTNAME»` is any host under your control (not just the Raspberry Pi running IOTstack); and
414414
* `«COMMAND»` is any command known to the target host.
415415

416-
### Assumptions
416+
### <a name="sshAssumptions"></a>Assumptions
417417

418418
* [SensorsIot/IOTstack](https://github.com/SensorsIot/IOTstack) is installed on your Raspberry Pi.
419419
* The Node-RED container is running.
420420

421421
These instructions are specific to IOTstack but the underlying concepts should apply to any installation of Node-RED in a Docker container.
422422

423-
### Executing commands "inside" a container
423+
### <a name="dockerExec"></a>Executing commands "inside" a container
424424

425425
These instructions make frequent use of the ability to run commands "inside" the Node-RED container. For example, suppose you want to execute:
426426

@@ -466,19 +466,19 @@ You have several options:
466466

467467
3. Run the command from Portainer by selecting the container, then clicking the ">_ console" link. This is identical to opening a shell.
468468

469-
### Variable definitions
469+
### <a name="variableDefinitions"></a>Variable definitions
470470

471471
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".
472472

473-
#### «HOSTNAME» (required)
473+
#### <a name="sshHostname"></a>«HOSTNAME» (required)
474474

475475
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:
476476

477477
```
478478
iot-dev
479479
```
480480

481-
#### <a name="sshHostAddr">«HOSTADDR» (required)</a>
481+
#### <a name="sshHostAddr"></a>«HOSTADDR» (required)
482482

483483
Either or both of the following:
484484

@@ -507,15 +507,15 @@ Either or both of the following:
507507
* a static DHCP assignment configured on your DHCP server (eg your router) which always returns the same IP address for a given MAC address; or
508508
* a static IP address configured on your Raspberry Pi.
509509

510-
#### <a name="sshUserID">«USERID» (required)</a>
510+
#### <a name="sshUserID"></a>«USERID» (required)
511511

512512
The user ID of the account on «HOSTNAME» where you want Node-RED flows to be able to run commands. Example:
513513

514514
```
515515
pi
516516
```
517517

518-
### Step 1: *Generate SSH key-pair for Node-RED* (one time)
518+
### <a name="sshStep1"></a>Step 1: *Generate SSH key-pair for Node-RED* (one time)
519519

520520
Create a key-pair for Node-RED. This is done by executing the `ssh-keygen` command **inside** the container:
521521

@@ -531,7 +531,7 @@ Notes:
531531
* press "y" to overwrite (and lose the old keys)
532532
* press "n" to terminate the command, after which you can investigate why a key-pair already exists.
533533

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)
535535

536536
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:
537537

@@ -581,7 +581,7 @@ and check to make sure that only the key(s) you wanted were added.
581581

582582
If you do not see an indication that a key has been added, you may need to retrace your steps.
583583

584-
### Step 3: *Perform the recommended test*
584+
### <a name="sshStep3"></a>Step 3: *Perform the recommended test*
585585

586586
The output above recommends a test. The test needs to be run **inside** the Node-RED container so the syntax is:
587587

@@ -602,9 +602,9 @@ If everything works as expected, you should see a list of the files in your IOTs
602602

603603
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.
604604

605-
### Understanding what's where and what each file does
605+
### <a name="sshWhatsWhere"></a>Understanding what's where and what each file does
606606

607-
#### What files are where
607+
#### <a name="sshFileLocations"></a>What files are where
608608

609609
Six files are relevant to Node-RED's ability to execute commands outside of container-space:
610610

@@ -617,7 +617,7 @@ Six files are relevant to Node-RED's ability to execute commands outside of cont
617617
618618
Unless you take precautions, those keys will change whenever your Raspberry Pi is rebuilt from scratch and that **will** stop SSH from working.
619619
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).
621621

622622
* in `~/IOTstack/volumes/nodered/ssh`:
623623

@@ -632,7 +632,7 @@ Six files are relevant to Node-RED's ability to execute commands outside of cont
632632

633633
If you lose or destroy these keys, SSH **will** stop working.
634634
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).
636636

637637
- `known_hosts`
638638

@@ -654,7 +654,7 @@ Six files are relevant to Node-RED's ability to execute commands outside of cont
654654
655655
Note that providing the correct password at the command line will auto-repair the `authorized_keys` file.
656656

657-
#### What each file does
657+
#### <a name="sshFilePurpose"></a>What each file does
658658

659659
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.
660660

@@ -664,7 +664,7 @@ SSH running **outside** container-space uses the Raspberry Pi's private host key
664664

665665
SSH running **inside** the Node-RED container verifies that assurance by using its copy of the Raspberry Pi's public host key stored in `known_hosts`.
666666

667-
### Config file (optional)
667+
### <a name="sshConfig"></a>Config file (optional)
668668

669669
You don't **have** to do this step but it will simplify your exec node commands and reduce your maintenance problems if you do.
670670

@@ -741,7 +741,7 @@ $ sudo chown root:root config
741741
$ sudo mv config ./volumes/nodered/ssh
742742
```
743743

744-
#### Re-test with config file in place
744+
#### <a name="sshConfigTest"></a>Re-test with config file in place
745745

746746
The previous test used this syntax:
747747

@@ -763,7 +763,7 @@ $ docker exec nodered ssh «HOSTNAME» ls -1 /home/pi/IOTstack
763763

764764
The result should be the same as the earlier test.
765765

766-
### A test flow
766+
### <a name="sshTestFlow"></a>A test flow
767767

768768
![node-red-exec-node-ssh-test](./images/nodered-exec-node-ssh-test.jpeg)
769769

@@ -805,7 +805,7 @@ In the Node-RED GUI:
805805
806806
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.
807807
808-
### Suppose you want to add another «HOSTNAME»
808+
### <a name="addHostname"></a>Suppose you want to add another «HOSTNAME»
809809
810810
1. Exchange keys with the new target host using:
811811
@@ -821,7 +821,7 @@ In the Node-RED GUI:
821821
822822
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.
823823
824-
## Upgrading Node-RED
824+
## <a name="upgradeNodeRed"></a>Upgrading Node-RED
825825
826826
You can update most containers like this:
827827
@@ -863,7 +863,7 @@ Your existing Node-RED container continues to run while the rebuild proceeds. On
863863
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.
864864

865865

866-
## Customising Node-RED
866+
## <a name="customiseNodeRed"></a>Customising Node-RED
867867

868868
You customise your *local* image of Node-RED by making changes to:
869869

@@ -881,7 +881,7 @@ $ docker system prune
881881

882882
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*.
883883

884-
### Node.js version
884+
### <a name="nodeJSversion"></a>Node.js version
885885

886886
Out of the box, IOTstack starts the Node-RED *Dockerfile* with:
887887

@@ -903,9 +903,9 @@ In the unlikely event that you need to run an add-on node that needs version 10
903903
FROM nodered/node-red:latest-10
904904
```
905905

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).
907907

908-
### Adding extra packages
908+
### <a name="addPackage"></a>Adding extra packages
909909

910910
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.
911911

@@ -927,13 +927,13 @@ RUN apk update && apk add --no-cache eudev-dev mosquitto-clients bind-tools tcpd
927927

928928
You can add as many extra packages as you like. They will persist until you change the *Dockerfile* again.
929929

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).
931931

932-
### Adding extra nodes
932+
### <a name="addNodes"></a>Adding extra nodes
933933

934934
You can install nodes by:
935935

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).
937937

938938
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*.
939939

@@ -997,7 +997,7 @@ If you're wondering about "backup", nodes installed via:
997997

998998
Basically, if you're running IOTstack backups then your add-on nodes will be backed-up.
999999

1000-
### Node precedence
1000+
### <a name="nodePrecedence"></a>Node precedence
10011001

10021002
Add-on nodes that are installed via *Dockerfile* wind up at the **internal** path:
10031003

@@ -1037,7 +1037,7 @@ take precedence over those installed at:
10371037

10381038
Or, to put it more simply: in any contest, Manage Palette prevails over *Dockerfile*.
10391039

1040-
### Resolving node duplication
1040+
### <a name="fixDuplicateNodes"></a>Resolving node duplication
10411041

10421042
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.
10431043

0 commit comments

Comments
 (0)