How to install python and other pre-requisites for node-red-contrib-machine-learning-v2 on a docker container

Hi @lei1

I have a blog post I've been working on but it's not quite ready to publish just yet, but here is section of it that I hope should help.


As well as the pre-built containers the node-red-docker project on github also contains the Dockerfile and scripts to build a version of the Node-RED Docker container based on the Debian Linux distribution. This uses the normal glibc library and also being a mainstream Linux distribution it is more likely to be used as the basis for instructions for install many libraries and pre-requisites for NodeJS nodes.

You can build the container locally by running the following commands:

$ git clone https://github.com/node-red/node-red-docker.git
$ cd node-red-docker /docker-custom
$ ./docker-debian.sh

This will build a container image called testing:node-red-build by default and which can be run as follows:

$ docker run -d -p 1880:1880 -v node_red_data:/data --name myNRtest testing:node-red-build

Now you have a debian based container it can either be used as the base for a new Dockerfile which can be used to add in any prerequisite libraries or applications.

For example to install the prerequisite libraries for node-red-contrib-machine-learning node the following Dockerfile will extend the output of the previous command and add the required python libraries.

FROM testing:node-red-build
USER root
RUN apt-get install -y python3-pip python3-numpy python3-pandas 
RUN pip install scikit-learn tensorflow
USER node-red

Another approach would be to edit the Dockerfile.debian found in the docker-custom directory mentioned earlier.

...
COPY --from=build /usr/src/node-red/prod_node_modules ./node_modules
# Chown, install devtools & Clean up

RUN chown -R node-red:root /usr/src/node-red && \
    apt-get update && apt-get install -y build-essential python-dev python3 \ 
    python3-pip python3-numpy python3-pandas && \
    pip install scikit-learn tensorflow && \
    rm -r /tmp/*
USER node-red
...
1 Like