|
| 1 | +--- |
| 2 | +layout: docs-getting-started |
| 3 | +title: Adding Prerequistes to Docker |
| 4 | +toc: toc-user-guide.html |
| 5 | +slug: docker-custom |
| 6 | +redirect_from: |
| 7 | + - /docs/platforms/docker-custom |
| 8 | +--- |
| 9 | + |
| 10 | +### Introduction |
| 11 | + |
| 12 | +The project makes available a number of different versions of the Docker container on [Docker hub](https://hub.docker.com/r/nodered/node-red/) which fall into 2 categories: |
| 13 | + |
| 14 | + - Different underlying NodeJS versions. As new NodeJS LTS versions are released coresponding versions of the container are added. |
| 15 | + - Images tagged with the `-minimal` suffix. These containers are designed to contian the absolute libraries required to run Node-RED and it's core nodes. |
| 16 | + |
| 17 | +Specifically the `-minimal` containers do not have the native build tools required to build some nodes components triggered by installing them. |
| 18 | + |
| 19 | +Both of these sets of images are based on the NodeJS Alpine containers. Alpine is a Linux distribution tha aims to provide the smallest possible install footprint, it is used as the base for many language runtime containers (e.g. NodeJS & Python). As part of a number of optomisations to reduce the size it uses the [musl](https://www.musl-libc.org/intro.html) libc instead of the usual glibc implementation. |
| 20 | + |
| 21 | +Musl works fine with most applications but on some occations it can cause problems e.g. with some of the [SAP](https://github.com/SAP/node-rfc/issues/148) nodes and with some low level video codec. |
| 22 | + |
| 23 | +If you want to extend the provided Docker containers then then you will need to use Apline's package management tool `apk` to install additional libraries or applications. |
| 24 | + |
| 25 | + FROM nodered/node-red:latest |
| 26 | + USER root |
| 27 | + apk add py3-pip py3-numpy py3-pandas py3-scikit-learn |
| 28 | + pip install tensorflow |
| 29 | + USER node-red |
| 30 | + |
| 31 | +### Debian based containers |
| 32 | + |
| 33 | +As well as the Alpine based containers the Node-RED Docker git project also includes a script to build a version of the Node-RED Docker containers based on the Debian Linux Distribution. This is useful as Debian is a more mainstream Linux distribution and many nodes include instructions on how to install prerequistes. |
| 34 | + |
| 35 | +You can build the containers locally by running the following commands: |
| 36 | + |
| 37 | + $ git clone https://github.com/node-red/node-red-docker.git |
| 38 | + $ cd node-red-docker/docker-custom |
| 39 | + $ ./docker-debian.sh |
| 40 | + |
| 41 | + |
| 42 | +This will a container called `testing:node-red-build` which can be run as follows: |
| 43 | + |
| 44 | + $ docker run -d -p 1880:1880 -v node_red_data:/data --name myNRtest testing:node-red-build |
| 45 | + |
| 46 | +This container can be extended to add the required prerequistes for your projects. For example to add the required libraries for the [node-red-contrib-machine-learning](https://flows.nodered.org/node/node-red-contrib-machine-learning) node the following Dockerfile will extend the previously built container. |
| 47 | + |
| 48 | + FROM testing:node-red-build |
| 49 | + USER root |
| 50 | + RUN apt-get install -y python3-pip python3-numpy python3-pandas |
| 51 | + RUN pip install scikit-learn tensorflow |
| 52 | + USER node-red |
| 53 | + |
| 54 | +This can be build with |
| 55 | + |
| 56 | + docker build . -t custom-node-red |
| 57 | + |
| 58 | +The other option is to edit the `Dockerfile.debian` to build in the dependencies up front. You can add the packages to the `apt-get` line and then add a `pip` to install the native Python modules not directly packaged for Debian. |
| 59 | + |
| 60 | + ... |
| 61 | + COPY --from=build /usr/src/node-red/prod_node_modules ./node_modules |
| 62 | + |
| 63 | + # Chown, install devtools & Clean up |
| 64 | + RUN chown -R node-red:root /usr/src/node-red && \ |
| 65 | + apt-get update && apt-get install -y build-essential python-dev python3 \ |
| 66 | + python3-pip python3-numpy python3-pandas && \ |
| 67 | + pip install scikit-learn tensorflow && \ |
| 68 | + rm -r /tmp/* |
| 69 | + |
| 70 | + USER node-red |
| 71 | + ... |
| 72 | + |
| 73 | +In this case you would just need to rerun the `docker-debian.sh` script. |
0 commit comments