Skip to content

Commit 2fd4ec7

Browse files
authored
Pull latest readme. volume updates etc across to master (#202)
1 parent 75486b9 commit 2fd4ec7

11 files changed

+205
-50
lines changed

Diff for: .docker/Dockerfile.alpine

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ WORKDIR /usr/src/node-red
3737

3838
# package.json contains Node-RED NPM module and node dependencies
3939
COPY package.json .
40+
COPY flows.json /data
4041

4142
#### Stage BUILD #######################################################################################################
4243
FROM base AS build
@@ -88,9 +89,6 @@ ENV NODE_RED_VERSION=$NODE_RED_VERSION \
8889
# ENV NODE_RED_ENABLE_SAFE_MODE=true # Uncomment to enable safe start mode (flows not running)
8990
# ENV NODE_RED_ENABLE_PROJECTS=true # Uncomment to enable projects option
9091

91-
# User configuration directory volume
92-
VOLUME ["/data"]
93-
9492
# Expose the listening port of node-red
9593
EXPOSE 1880
9694

Diff for: README.md

+39-30
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ Previous 0.20.x versions are still available at https://hub.docker.com/r/nodered
1515
## Quick Start
1616
To run in Docker in its simplest form just run:
1717

18-
docker run -it -p 1880:1880 --name mynodered nodered/node-red
18+
docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red
1919

2020
Let's dissect that command:
2121

2222
docker run - run this container, initially building locally if necessary
2323
-it - attach a terminal session so we can see what is going on
2424
-p 1880:1880 - connect local port 1880 to the exposed internal port 1880
25+
-v node_red_data:/data - mount the host node_red_data directory to the container /data directory so any changes made to flows are persisted
2526
--name mynodered - give this machine a friendly local name
2627
nodered/node-red - the image to base it on - currently Node-RED v1.1.3
2728

@@ -101,7 +102,7 @@ The minimal versions (without python and build tools) are not able to install no
101102

102103
For example - to run the latest minimal version, you would run
103104
```
104-
docker run -it -p 1880:1880 --name mynodered nodered/node-red:latest-minimal
105+
docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red:latest-minimal
105106
```
106107

107108
The Node-RED images are based on [official Node JS Alpine Linux](https://hub.docker.com/_/node/) images to keep them as small as possible.
@@ -186,7 +187,7 @@ Therefore all tags regarding Raspberry PI's are dropped.
186187

187188
For example: suppose you are running on a Raspberry PI 3B, which has `arm32v7` as architecture. Then just run the following command to pull the image (tagged by `1.1.3-10-arm32v7`), and run the container.
188189
```
189-
docker run -it -p 1880:1880 --name mynodered nodered/node-red:latest
190+
docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red:latest
190191
```
191192

192193
The same command can be used for running on an amd64 system, since docker discovers its running on a amd64 host and pulls the image with the matching tag (`1.1.3-10-amd64`).
@@ -195,7 +196,8 @@ This gives the advantage that you don't need to know/specify which architecture
195196

196197
**Note**: Currently there is a bug in Docker's architecture detection that fails for `arm32v6` - eg Raspberry Pi Zero or 1. For these devices you currently need to specify the full image tag, for example:
197198
```
198-
docker run -it -p 1880:1880 --name mynodered nodered/node-red:1.1.3-10-minimal-arm32v6
199+
docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red:1.1.3-10-minimal-arm32v6
200+
199201
```
200202

201203
## Raspberry PI - native GPIO support
@@ -256,17 +258,17 @@ to store persistent or shared data outside the container.
256258
To create a new named data volume to persist our user data and run a new
257259
container using this volume.
258260

259-
$ docker volume create --name node_red_user_data
261+
$ docker volume create --name node_red_data_vol
260262
$ docker volume ls
261263
DRIVER VOLUME NAME
262-
local node_red_user_data
263-
$ docker run -it -p 1880:1880 -v node_red_user_data:/data --name mynodered nodered/node-red
264+
local node_red_data_vol
265+
$ docker run -it -p 1880:1880 -v node_red_data_vol:/data --name mynodered nodered/node-red
264266

265267
Using Node-RED to create and deploy some sample flows, we can now destroy the
266268
container and start a new instance without losing our user data.
267269

268270
$ docker rm mynodered
269-
$ docker run -it -p 1880:1880 -v node_red_user_data:/data --name mynodered nodered/node-red
271+
$ docker run -it -p 1880:1880 -v node_red_data_vol:/data --name mynodered nodered/node-red
270272

271273
## Updating
272274

@@ -350,7 +352,7 @@ The flows configuration file is set using an environment parameter (**FLOWS**),
350352
which defaults to *'flows.json'*. This can be changed at runtime using the
351353
following command-line flag.
352354
```
353-
docker run -it -p 1880:1880 -e FLOWS=my_flows.json nodered/node-red
355+
docker run -it -p 1880:1880 -e FLOWS=my_flows.json -v node_red_data:/data nodered/node-red
354356
```
355357

356358
**Note**: If you set `-e FLOWS=""` then the flow file can be set via the *flowFile*
@@ -360,7 +362,7 @@ Node.js runtime arguments can be passed to the container using an environment
360362
parameter (**NODE_OPTIONS**). For example, to fix the heap size used by
361363
the Node.js garbage collector you would use the following command.
362364
```
363-
docker run -it -p 1880:1880 -e NODE_OPTIONS="--max_old_space_size=128" nodered/node-red
365+
docker run -it -p 1880:1880 -e NODE_OPTIONS="--max_old_space_size=128" -v node_red_data:/data nodered/node-red
364366
```
365367

366368
Other useful environment variables include
@@ -439,49 +441,55 @@ docker id number and be running on a random port... to find out run
439441
You can now point a browser to the host machine on the tcp port reported back, so in the example
440442
above browse to `http://{host ip}:49154`
441443

444+
**NOTE**: as this does not mount the `/data` volume externally any changes to flows will not be saved and if the container is redeployed or upgraded these will be lost. The volume may persist on the host filing sysem and can probably be retrieved and remounted if required.
445+
442446
## Linking Containers
443447

444-
You can link containers "internally" within the docker runtime by using the --link option.
448+
You can link containers "internally" within the docker runtime by using Docker [user-defined bridges](https://docs.docker.com/network/bridge/).
449+
450+
Before using a bridge, it needs to be created. The command below will create a new bridge called **iot**
451+
452+
docker network create iot
445453

446-
For example I have a simple MQTT broker container available as
454+
Then all containers that need to communicate need to be added to the same bridge using the **--network** command line option
447455

448-
docker run -it --name mybroker eclipse-mosquitto
456+
docker run -itd --network iot --name mybroker eclipse-mosquitto
449457

450458
(no need to expose the port 1883 globally unless you want to... as we do magic below)
451459

452-
Then run nodered docker - but this time with a link parameter (name:alias)
460+
Then run nodered docker, also added to the same bridge
453461

454-
docker run -it -p 1880:1880 --name mynodered --link mybroker:broker nodered/node-red
462+
docker run -itd -p 1880:1880 --network iot --name mynodered nodered/node-red
455463

456-
the magic here being the `--link` that inserts a entry into the node-red instance
457-
hosts file called *broker* that links to the external mybroker instance.... but we do
458-
expose the 1880 port so we can use an external browser to do the node-red editing.
464+
containers on the same user-defined bridge can take advantage of the built in name resolution provided by the bridge and use the container name (specified using the **--name** option) as the target hostname.
459465

460-
Then a simple flow like below should work - using the alias *broker* we just set up a second ago.
461466

462-
[{"id":"190c0df7.e6f3f2","type":"mqtt-broker","broker":"broker","port":"1883","clientid":""},{"id":"37963300.c869cc","type":"mqtt in","name":"","topic":"test","broker":"190c0df7.e6f3f2","x":226,"y":244,"z":"f34f9922.0cb068","wires":[["802d92f9.7fd27"]]},{"id":"edad4162.1252c","type":"mqtt out","name":"","topic":"test","qos":"","retain":"","broker":"190c0df7.e6f3f2","x":453,"y":135,"z":"f34f9922.0cb068","wires":[]},{"id":"13d1cf31.ec2e31","type":"inject","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":226,"y":157,"z":"f34f9922.0cb068","wires":[["edad4162.1252c"]]},{"id":"802d92f9.7fd27","type":"debug","name":"","active":true,"console":"false","complete":"false","x":441,"y":261,"z":"f34f9922.0cb068","wires":[]}]
467+
In the above example the broker can be reached from the Node-RED application using hostname *mybroker*.
468+
469+
Then a simple flow like below show the mqtt nodes connecting to the broker
470+
471+
[{"id":"c51cbf73.d90738","type":"mqtt in","z":"3fa278ec.8cbaf","name":"","topic":"test","broker":"5673f1d5.dd5f1","x":290,"y":240,"wires":[["7781c73.639b8b8"]]},{"id":"7008d6ef.b6ee38","type":"mqtt out","z":"3fa278ec.8cbaf","name":"","topic":"test","qos":"","retain":"","broker":"5673f1d5.dd5f1","x":517,"y":131,"wires":[]},{"id":"ef5b970c.7c864","type":"inject","z":"3fa278ec.8cbaf","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":290,"y":153,"wires":[["7008d6ef.b6ee38"]]},{"id":"7781c73.639b8b8","type":"debug","z":"3fa278ec.8cbaf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":505,"y":257,"wires":[]},{"id":"5673f1d5.dd5f1","type":"mqtt-broker","z":"","name":"","broker":"mybroker","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]
463472

464473
This way the internal broker is not exposed outside of the docker host - of course
465-
you may add `-p 1883:1883` etc to the broker run command if you want to see it...
474+
you may add `-p 1883:1883` etc to the broker run command if you want other systems outside your computer to be able to use the broker.
466475

467476
### Docker-Compose linking example
468477

469478
Another way to link containers is by using docker-compose. The following docker-compose.yml
470-
file creates a Node-RED instance, and a local MQTT broker instance. In the Node-RED flow the broker can be addressed simply as `broker` at its default port `1883`.
479+
file creates a Node-RED instance, and a local MQTT broker instance. In the Node-RED flow the broker can be addressed simply as `mybroker` at its default port `1883`.
471480

472481
```
473482
version: "3.7"
474483
475484
services:
476-
node-red:
485+
mynodered:
477486
image: nodered/node-red
478487
restart: unless-stopped
479488
volumes:
480489
- /home/pi/.node-red:/data
481490
ports:
482491
- 1880:1880
483-
484-
broker:
492+
mybroker:
485493
image: eclipse-mosquitto
486494
restart: unless-stopped
487495
```
@@ -492,12 +500,12 @@ Sometimes it is useful to debug the code which is running inside the container.
492500

493501
1. In most cases the *'debug'* script will be sufficient, to debug a Node-RED application that is fully up-and-running (i.e. when the application startup code is not relevant). The NodeJs server can be started in debug mode using following command:
494502
```
495-
docker run -it -p 1880:1880 -p 9229:9229 --name mynodered --entrypoint npm nodered/node-red run debug -- --userDir /data
503+
docker run -it -p 1880:1880 -p 9229:9229 -v node_red_data:/data --name mynodered --entrypoint npm nodered/node-red run debug -- --userDir /data
496504
```
497505

498506
2. In case debugging of the Node-RED startup code is required, the *'debug_brk'* script will instruct NodeJs to break at the first statement of the Node-RED application. The NodeJs server can be started in debug mode using following command:
499507
```
500-
docker run -it -p 1880:1880 -p 9229:9229 --name mynodered --entrypoint npm nodered/node-red run debug_brk -- --userDir /data
508+
docker run -it -p 1880:1880 -p 9229:9229 -v node_red_data:/data --name mynodered --entrypoint npm nodered/node-red run debug_brk -- --userDir /data
501509
```
502510
Note that in this case NodeJs will wait - at the first statement of the Node-RED application - until a debugger client connects...
503511

@@ -512,6 +520,7 @@ Let's dissect both commands:
512520
-it - attach a terminal session so we can see what is going on
513521
-p 1880:1880 - connect local port 1880 to the exposed internal port 1880
514522
-p 9229:9229 - connect local port 9229 to the exposed internal port 9229 (for debugger communication)
523+
-v node_red_data:/data - mount the internal /data to the host mode_red_data directory
515524
--name mynodered - give this machine a friendly local name
516525
--entrypoint npm - overwrite the default entrypoint (which would run the *'start'* script)
517526
nodered/node-red - the image to base it on - currently Node-RED v1.1.0
@@ -533,7 +542,7 @@ on permissions.
533542
If you are seeing *permission denied* errors opening files or accessing host devices, try running the container as the root user.
534543

535544
```
536-
docker run -it -p 1880:1880 --name mynodered -u root nodered/node-red
545+
docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered -u root nodered/node-red
537546
```
538547

539548
__References:__
@@ -549,7 +558,7 @@ https://github.com/node-red/node-red/issues/8
549558
If you want to access a device from the host inside the container, e.g. serial port, use the following command-line flag to pass access through.
550559

551560
```
552-
docker run -it -p 1880:1880 --name mynodered --device=/dev/ttyACM0 nodered/node-red
561+
docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered --device=/dev/ttyACM0 nodered/node-red
553562
```
554563
__References:__
555564

@@ -562,7 +571,7 @@ https://github.com/node-red/node-red/issues/15
562571
If you want to modify the default timezone, use the TZ environment variable with the [relevant timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
563572

564573
```
565-
docker run -it -p 1880:1880 --name mynodered -e TZ=Europe/London nodered/node-red
574+
docker run -it -p 1880:1880 -v node_red_data:/data --name mynodered -e TZ=Europe/London nodered/node-red
566575
```
567576

568577
__References:__

Diff for: docker-custom/Dockerfile.custom

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG ARCH=amd64
2-
ARG NODE_VERSION=10
2+
ARG NODE_VERSION=12
33
ARG OS=alpine
44

55
#### Stage BASE ########################################################################################################
@@ -32,6 +32,7 @@ WORKDIR /usr/src/node-red
3232

3333
# package.json contains Node-RED NPM module and node dependencies
3434
COPY package.json .
35+
COPY flows.json /data
3536

3637
#### Stage BUILD #######################################################################################################
3738
FROM base AS build
@@ -81,9 +82,6 @@ ENV NODE_RED_VERSION=$NODE_RED_VERSION \
8182
# ENV NODE_RED_ENABLE_SAFE_MODE=true # Uncomment to enable safe start mode (flows not running)
8283
# ENV NODE_RED_ENABLE_PROJECTS=true # Uncomment to enable projects option
8384

84-
# User configuration directory volume
85-
VOLUME ["/data"]
86-
8785
# Expose the listening port of node-red
8886
EXPOSE 1880
8987

Diff for: docker-custom/Dockerfile.debian

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
ARG ARCH=amd64
2+
ARG NODE_VERSION=12
3+
ARG OS=buster-slim
4+
5+
#### Stage BASE ########################################################################################################
6+
FROM ${ARCH}/node:${NODE_VERSION}-${OS} AS base
7+
8+
# Copy scripts
9+
COPY scripts/*.sh /tmp/
10+
11+
# Install tools, create Node-RED app and data dir, add user and set rights
12+
RUN set -ex && \
13+
apt-get update && apt-get install -y \
14+
bash \
15+
tzdata \
16+
curl \
17+
nano \
18+
wget \
19+
git \
20+
openssl \
21+
openssh-client && \
22+
mkdir -p /usr/src/node-red /data && \
23+
deluser --remove-home node && \
24+
# adduser --home /usr/src/node-red --disabled-password --no-create-home node-red --uid 1000 && \
25+
useradd --home-dir /usr/src/node-red --uid 1000 node-red && \
26+
chown -R node-red:root /data && chmod -R g+rwX /data && \
27+
chown -R node-red:root /usr/src/node-red && chmod -R g+rwX /usr/src/node-red
28+
# chown -R node-red:node-red /data && \
29+
# chown -R node-red:node-red /usr/src/node-red
30+
31+
# Set work directory
32+
WORKDIR /usr/src/node-red
33+
34+
# package.json contains Node-RED NPM module and node dependencies
35+
COPY package.json .
36+
COPY flows.json /data
37+
38+
#### Stage BUILD #######################################################################################################
39+
FROM base AS build
40+
41+
# Install Build tools
42+
RUN apt-get update && apt-get install -y build-essential python && \
43+
npm install --unsafe-perm --no-update-notifier --no-fund --only=production && \
44+
npm uninstall node-red-node-gpio && \
45+
cp -R node_modules prod_node_modules
46+
47+
#### Stage RELEASE #####################################################################################################
48+
FROM base AS RELEASE
49+
ARG BUILD_DATE
50+
ARG BUILD_VERSION
51+
ARG BUILD_REF
52+
ARG NODE_RED_VERSION
53+
ARG ARCH
54+
ARG TAG_SUFFIX=default
55+
56+
LABEL org.label-schema.build-date=${BUILD_DATE} \
57+
org.label-schema.docker.dockerfile=".docker/Dockerfile.debian" \
58+
org.label-schema.license="Apache-2.0" \
59+
org.label-schema.name="Node-RED" \
60+
org.label-schema.version=${BUILD_VERSION} \
61+
org.label-schema.description="Low-code programming for event-driven applications." \
62+
org.label-schema.url="https://nodered.org" \
63+
org.label-schema.vcs-ref=${BUILD_REF} \
64+
org.label-schema.vcs-type="Git" \
65+
org.label-schema.vcs-url="https://github.com/node-red/node-red-docker" \
66+
org.label-schema.arch=${ARCH} \
67+
authors="Dave Conway-Jones, Nick O'Leary, James Thomas, Raymond Mouthaan"
68+
69+
COPY --from=build /usr/src/node-red/prod_node_modules ./node_modules
70+
71+
# Chown, install devtools & Clean up
72+
RUN chown -R node-red:root /usr/src/node-red && \
73+
apt-get update && apt-get install -y build-essential python-dev python3 && \
74+
rm -r /tmp/*
75+
76+
USER node-red
77+
78+
# Env variables
79+
ENV NODE_RED_VERSION=$NODE_RED_VERSION \
80+
NODE_PATH=/usr/src/node-red/node_modules:/data/node_modules \
81+
FLOWS=flows.json
82+
83+
# ENV NODE_RED_ENABLE_SAFE_MODE=true # Uncomment to enable safe start mode (flows not running)
84+
# ENV NODE_RED_ENABLE_PROJECTS=true # Uncomment to enable projects option
85+
86+
# Expose the listening port of node-red
87+
EXPOSE 1880
88+
89+
# Add a healthcheck (default every 30 secs)
90+
# HEALTHCHECK CMD curl http://localhost:1880/ || exit 1
91+
92+
ENTRYPOINT ["npm", "start", "--cache", "/data/.npm", "--", "--userDir", "/data"]

0 commit comments

Comments
 (0)