'Docker compose for node project

I'm trying to updated (fool me) a node project built with nuxt and prepare a DockerFile and respective docker compose for it.

The build runs fine, but when execute docker-compose up this is the error:

e_nuxt-web-1  | Error: Missing binding /app/node_modules/node-sass/vendor/linux-x64-72/binding.node
e_nuxt-web-1  | Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 12.x
e_nuxt-web-1  | 
e_nuxt-web-1  | Found bindings for the following environments:
e_nuxt-web-1  |   - OS X 64-bit with Unsupported runtime (102)
e_nuxt-web-1  |   - OS X 64-bit with Node.js 12.x

This is the DockerFile:

FROM node:12.18.0

WORKDIR /app

COPY . .

RUN apt-get update || : && apt-get install -y \
    python \
    build-essential

RUN npm install

RUN npm install typescript

RUN npm rebuild node-sass --force

ENV HOST 0.0.0.0
EXPOSE 3000

CMD [ "npm", "run", "dev" ]

dockercompose.yml

version: "3.4"

services:

  web:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/app

As you see I'm installing some missing parts to the node image (is there a better starting image for node projects?) and then trying to rebuild node-sass because this finding: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (88)

But as you see the error says the binding was built with "OS X", where the running container is Linux. Apparently this rebuild --force doesn't do what I expect, how should I force to rebuild the library for the proper OS?

Updating nuxt is a nightmare so I'd like to recreate the expected running environment for that version of nuxt which uses node-sass ^4.14.1 (which works with node12). While delving a bit more I see some suggestions about deleting the node-sass folder inside node-modules, why would that even make a difference?



Solution 1:[1]

You are mounting your project directory (with all files either hidden or not) to the service container.

This configuration basically benefits if you are trying to have your changes reflected in realtime to your container while I doubt you are looking for this based on your installation description.

You should omit the volumes key in your docker-compose.yml file:

version: "3.4"

services:

  web:
    build: .
    ports:
      - "3000:3000"

You should instruct docker to ignore your host node_modules directory as well. Add the directory name into your dockerignore config file (living in top of your project directory):

# other ignored files
node_modules

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tmarwen