Skip to content

Commit ed549ff

Browse files
authored
Merge dev to master for permission changes (#180)
* [skip travis] change perms to allow openshift to load more easily * Update README.md * permissions update for openshift * and add cache to entrypoint
1 parent 84d7514 commit ed549ff

File tree

5 files changed

+52
-12
lines changed

5 files changed

+52
-12
lines changed

.docker/Dockerfile.alpine

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ RUN set -ex && \
2727
mkdir -p /usr/src/node-red /data && \
2828
deluser --remove-home node && \
2929
adduser -h /usr/src/node-red -D -H node-red -u 1000 && \
30-
chown -R node-red:node-red /data && \
31-
chown -R node-red:node-red /usr/src/node-red
30+
chown -R node-red:root /data && chmod -R g+rwX /data && \
31+
chown -R node-red:root /usr/src/node-red && chmod -R g+rwX /usr/src/node-red
32+
# chown -R node-red:node-red /data && \
33+
# chown -R node-red:node-red /usr/src/node-red
3234

3335
# Set work directory
3436
WORKDIR /usr/src/node-red
@@ -71,7 +73,7 @@ LABEL org.label-schema.build-date=${BUILD_DATE} \
7173
COPY --from=build /usr/src/node-red/prod_node_modules ./node_modules
7274

7375
# Chown, install devtools & Clean up
74-
RUN chown -R node-red:node-red /usr/src/node-red && \
76+
RUN chown -R node-red:root /usr/src/node-red && \
7577
/tmp/install_devtools.sh && \
7678
rm -r /tmp/* && \
7779
rm /usr/bin/qemu-$QEMU_ARCH-static
@@ -95,4 +97,4 @@ EXPOSE 1880
9597
# Add a healthcheck (default every 30 secs)
9698
HEALTHCHECK CMD node /healthcheck.js
9799

98-
ENTRYPOINT ["npm", "start", "--", "--userDir", "/data"]
100+
ENTRYPOINT ["npm", "start", "--cache", "/data/.npm", "--", "--userDir", "/data"]

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
[![DockerHub Stars](https://img.shields.io/docker/stars/nodered/node-red.svg?maxAge=2592000)](https://hub.docker.com/r/nodered/node-red/)
77

88
This project describes some of the many ways Node-RED can be run under Docker and has support for multiple architectures (amd64, arm32v6, arm32v7, arm64v8, i386 and s390x).
9-
Some basic familiarity with Docker and the [Docker Command Line](https://docs.docker.com/engine/reference/commandline/cli/) is assumed.
9+
Some basic familiarity with Docker and the [Docker Command Line](https://docs.docker.com/engine/reference/commandline/cli/) is assumed.
1010

11-
As of Node-RED 1.0 this project provides the build for the `nodered/node-red` container on [Docker Hub](https://hub.docker.com/r/nodered/node-red/). Note: the Docker Hub name has changed to `nodered/node-red`.
11+
As of Node-RED 1.0 this project provides the build for the `nodered/node-red` container on [Docker Hub](https://hub.docker.com/r/nodered/node-red/).
1212

1313
Previous 0.20.x versions are still available at https://hub.docker.com/r/nodered/node-red-docker.
1414

@@ -474,6 +474,38 @@ services:
474474
restart: unless-stopped
475475
```
476476

477+
## Debugging containers
478+
479+
Sometimes it is useful to debug the code which is running inside the container. Two scripts (*'debug'* and *'debug_brk'* in the package.json file) are available to start NodeJs in debug mode, which means that NodeJs will start listening (to port 9229) for a debug client. Various remote debugger tools (like Visual Code, Chrome Developer Tools ...) can be used to debug a Node-RED application. A [wiki](https://github.com/node-red/node-red-docker/wiki/Debug-container-via-Chrome-Developer-Tools) page has been provided, to explain step-by-step how to use the Chrome Developer Tools debugger.
480+
481+
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:
482+
```
483+
docker run -it -p 1880:1880 -p 9229:9229 --name mynodered --entrypoint npm nodered/node-red run debug -- --userDir /data
484+
```
485+
486+
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:
487+
```
488+
docker run -it -p 1880:1880 -p 9229:9229 --name mynodered --entrypoint npm nodered/node-red run debug_brk -- --userDir /data
489+
```
490+
Note that in this case NodeJs will wait - at the first statement of the Node-RED application - until a debugger client connects...
491+
492+
As soon as NodeJs is listening to the debug port, this will be shown in the startup log:
493+
```
494+
Debugger listening on ws://0.0.0.0:9229/...
495+
```
496+
497+
Let's dissect both commands:
498+
499+
docker run - run this container, initially building locally if necessary
500+
-it - attach a terminal session so we can see what is going on
501+
-p 1880:1880 - connect local port 1880 to the exposed internal port 1880
502+
-p 9229:9229 - connect local port 9229 to the exposed internal port 9229 (for debugger communication)
503+
--name mynodered - give this machine a friendly local name
504+
--entrypoint npm - overwrite the default entrypoint (which would run the *'start'* script)
505+
nodered/node-red - the image to base it on - currently Node-RED v1.0.3
506+
run debug(_brk) - (npm) arguments for the custom endpoint (which must be added AFTER the image name!)
507+
-- - the arguments that will follow are not npm arguments, but need to be passed to the script
508+
--userDir /data - instruct the script where the Node-RED data needs to be stored
477509

478510
## Common Issues and Hints
479511

docker-custom/Dockerfile.custom

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ RUN set -ex && \
2222
mkdir -p /usr/src/node-red /data && \
2323
deluser --remove-home node && \
2424
adduser -h /usr/src/node-red -D -H node-red -u 1000 && \
25-
chown -R node-red:node-red /data && \
26-
chown -R node-red:node-red /usr/src/node-red
25+
chown -R node-red:root /data && chmod -R g+rwX /data && \
26+
chown -R node-red:root /usr/src/node-red && chmod -R g+rwX /usr/src/node-red
27+
# chown -R node-red:node-red /data && \
28+
# chown -R node-red:node-red /usr/src/node-red
2729

2830
# Set work directory
2931
WORKDIR /usr/src/node-red
@@ -65,7 +67,7 @@ LABEL org.label-schema.build-date=${BUILD_DATE} \
6567
COPY --from=build /usr/src/node-red/prod_node_modules ./node_modules
6668

6769
# Chown, install devtools & Clean up
68-
RUN chown -R node-red:node-red /usr/src/node-red && \
70+
RUN chown -R node-red:root /usr/src/node-red && \
6971
/tmp/install_devtools.sh && \
7072
rm -r /tmp/*
7173

@@ -88,4 +90,4 @@ EXPOSE 1880
8890
# Add a healthcheck (default every 30 secs)
8991
# HEALTHCHECK CMD curl http://localhost:1880/ || exit 1
9092

91-
ENTRYPOINT ["npm", "start", "--", "--userDir", "/data"]
93+
ENTRYPOINT ["npm", "start", "--cache", "/data/.npm", "--", "--userDir", "/data"]

docker-custom/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
},
1111
"main": "node_modules/node-red/red/red.js",
1212
"scripts": {
13-
"start": "node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS"
13+
"start": "node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS",
14+
"debug": "node --inspect=0.0.0.0:9229 $NODE_OPTIONS node_modules/node-red/red.js $FLOWS",
15+
"debug_brk": "node --inspect=0.0.0.0:9229 --inspect-brk $NODE_OPTIONS node_modules/node-red/red.js $FLOWS"
1416
},
1517
"contributors": [
1618
{

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
},
1111
"main": "node_modules/node-red/red/red.js",
1212
"scripts": {
13-
"start": "node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS"
13+
"start": "node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS",
14+
"debug": "node --inspect=0.0.0.0:9229 $NODE_OPTIONS node_modules/node-red/red.js $FLOWS",
15+
"debug_brk": "node --inspect=0.0.0.0:9229 --inspect-brk $NODE_OPTIONS node_modules/node-red/red.js $FLOWS"
1416
},
1517
"contributors": [
1618
{

0 commit comments

Comments
 (0)