I am setting up a docker container using nodejs 4.2.4 with expressjs using sass.
My Dockerfile:
FROM node:4.2.4-wheezy
COPY myapp /srv/www/
RUN rm -r /srv/www/node_modules || echo "Not removing /srv/www/node_modules, directory did not exist"
#RUN npm update
#RUN npm install -g --silent node-sass
RUN cd /srv/www && npm install --silent
#RUN cd /srv/www && npm rebuild node-sass
EXPOSE 3000
The express.js project was generated using their generator
express -css sass --hbs myapp
which generates a skeleton project with this package.json:
{
"name": "myapp",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"hbs": "~3.1.0",
"morgan": "~1.6.1",
"node-sass-middleware": "0.8.0",
"serve-favicon": "~2.3.0"
}
}
Running this on my mac with node 4.2.4 works fine, but running it within the docker container gives the following error:
philipp@Philipps-MacBook-Pro:~/node/expressv1 $docker run -it -P -w="/srv/www/" test_server_7 npm start
npm info it worked if it ends with ok
npm info using npm@2.14.12
npm info using node@v4.2.4
npm info prestart myapp@0.0.0
npm info start myapp@0.0.0
> myapp@0.0.0 start /srv/www
> node ./bin/www
/srv/www/node_modules/node-sass-middleware/node_modules/node-sass/lib/extensions.js:158
throw new Error([
^
Error: The `libsass` binding was not found in /srv/www/node_modules/node-sass-middleware/node_modules/node-sass/vendor/linux-x64-46/binding.node
This usually happens because your node version has changed.
Run `npm rebuild node-sass` to build the binding for your current node version.
at Object.sass.getBinaryPath (/srv/www/node_modules/node-sass-middleware/node_modules/node-sass/lib/extensions.js:158:11)
at Object.<anonymous> (/srv/www/node_modules/node-sass-middleware/node_modules/node-sass/lib/index.js:16:36)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/srv/www/node_modules/node-sass-middleware/middleware.js:3:12)
at Module._compile (module.js:435:26)
However, if I extend the docker image from 5.4.1-wheezy it works fine. There seem to be quite some problems with libsass and node (here, here and here). I tried all of the suggestions in those links with some still remaining in the Dockerfile above, but none of them had any effect. In a way it also does not make sense to me that I would have to rebuild node-sass if I am coming from a clean node installation. Any suggestions?