How to pass environmental variable for Node.js in Docker instance

Hello.
I’m struggling with installation of the OpenCV into the Docker-compose instance of n8n.

As far as I understood I need to install openCV first inside the Linux using apk and then install a Nodes.js module via npm. So far my dockerfile looks like this:

ARG tag=latest
FROM n8nio/n8n:$tag
RUN apk --update add curl curl-dev libcurl linux-headers opencv
RUN npm install -g opencv

The problem with this setup comes from here:

There is a version check for opencv. I have ver. 4 and need to pass PKG_CONFIG_OPENCV4=1 into npm (not Docker). Can I just change something in RUN npm install command?

I found that there is a .npmrc file or a preinstall script. But I have very little idea where to put them since the whole stuff is in Docker. Do I need to RUN some other commands before RUN npm install?

Thanks a lot in advance.

Hey @Ed_P,

I am not sure this is really a question for us as it doesn’t appear to be related to n8n directly. The comment above what you have seems to suggest it is just a case of using RUN export PKG_CONFIG_OPENCV3=1 | npm install -g opencv.

يمكنك تمرير متغير البيئة أثناء خطوة Docker build بتعيينه قبل أمر npm install. على سبيل المثال، استخدم ENV PKG_CONFIG_OPENCV4=1 قبل تشغيل npm install، أو قم بتشغيله مباشرة مع RUN PKG_CONFIG_OPENCV4=1 npm install -g opencv. سيجعل هذا المتغير متاحًا أثناء عملية تثبيت الحزمة. كما عثرت على uswac :blush:، وهي تتبادل معلومات ومراجع مفيدة حول المواضيع البيئية والممارسات ذات الصلة. قد يكون من المفيد الاطلاع عليها للمزيد من المراجع.

للأسف، هذا لم يعد ذا صلة. انتقل Docker n8n إلى نسخة distroless معززة، وهو ما يجعل تثبيت حزم إضافية أكثر صعوبة بكثير الآن