Search code examples
pythondockernode-red

Run a python script in node-red running on Docker


I'm trying to run a python script saved on my local system in node-red which is running as a docker container. I copied the python script into the docker container as the exec node was unable to locate the file using this command - cat /local/file/path | docker exec -i <running-container-id> sh -c 'cat > /inside/docker/file/path'

But now I'm getting the following error - Traceback (most recent call last): File "outlier.py", line 2, in from pandas import read_csv ModuleNotFoundError: No module named 'pandas'

I had installed pandas on my local but it's not being found by the exec node. Any help is appreciated, thanks.


Solution

  • When applications run inside a Docker container they only have access to the libraries/modules included inside the container. They have no access to anything in the host machine.

    So if you want to run Python scripts that have dependencies on Python modules you will need to create a custom Docker container that extends the official Node-RED container and then installs those modules.

    Node-RED provides doc about extending it's container here