Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Node-sass binding problem in Docker container

There is problem with mounting volume with source code of my angular app in running Docker container.

My host OS is Win 10 64 bit.

This is my Dockerfile which is in root folder of app.

# base image
FROM node:10

# set working directory
RUN mkdir /usr/src/app
WORKDIR /usr/src/app

# install and cache app dependencies
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install -g @angular/[email protected]
RUN npm install node-sass@latest
RUN npm rebuild node-sass

# add app
COPY . /usr/src/app

# start app
CMD ng serve --host 

Rows about installing and rebuild Node-sass are efforts to fix problem, probably, there should be here.

So I start building docker container

docker build -t my-cool-app .

Then running: I want to mount source code from my host machine into container:

docker run -it -v ${PWD}:/usr/src/app -v ${PWD}/node_modules -p 4200:4200  my-cool-app

App starts compilation and I get error.

Module build failed (from ./node_modules/sass-loader/lib/loader.js): Error: Missing binding /usr/src/app/node_modules/node-sass/vendor/linux-x64-64/binding.node Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 10.x

Found bindings for the following environments: - Windows 64-bit with Node.js 10.x

I understand problem: node-sass builds on windows host as binary code and there is no binding to be started in Linux. As guys from here https://github.com/sass/node-sass/issues/2165 said - hey, rebuild node-sass after installation - I added such commands to Docker file but still failed.

like image 819
Eugene Shmorgun Avatar asked Mar 04 '23 04:03

Eugene Shmorgun

2 Answers

The problem is that you are copying the node_modules folder from your local environment as part of step 3. Make sure you create a .dockerignore file and add the node_modules folder. Once you do that, you won't need to do npm rebuild

like image 125
Yago Avatar answered Mar 06 '23 17:03


I've also been battling this for a number of days. I've finally had some success. I needed to clean the cache and also rebuild node-sass. Below is my Dockerfile:

FROM node:10.13-alpine as build     
WORKDIR /usr/src/app
COPY ["pap-ui/package.json", "/usr/src/app/"]
RUN npm install @angular/[email protected] -g
RUN npm cache clean --force
RUN npm install --save-dev

COPY . /usr/src/app

WORKDIR /usr/src/app/pap-ui
RUN npm rebuild node-sass --force
RUN npm run build

# Build a small nginx image with static website
FROM nginx:alpine
RUN rm -rf /usr/share/nginx/html/*
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/pap-ui/dist/pap-ui /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
like image 41
sarin Avatar answered Mar 06 '23 16:03