Error while running dockerfile

1

I have a dockerfile that runs an application on node.js

FROM node

RUN npm install mongoose

RUN useradd --user-group --create-home --shell /bin/false app &&\
  npm install --global [email protected]

ENV HOME=/home/app

COPY package.json $HOME/library/
RUN chown -R app:app $HOME/*

USER app
WORKDIR $HOME/library
RUN npm install --silent --progress=false

USER root
COPY . $HOME/library
RUN chown -R app:app $HOME/*
USER app

CMD ["npm", "start"]

and a docker-compose.yml

version: '2'
services:
  db:
    image: mongo
    command: "mongod"
    ports:
      - "27018:27018"
  library:
    build:
      context: .
      dockerfile: Dockerfile
    command: node_modules/.bin/nodemon --exec npm start
    environment:
      NODE_ENV: development
    ports:
      - 8080:8080
    volumes:
      - .:/home/app/library
      - /home/app/library/node_modules
    links:
      - db

After running docker-compose build I try to run with docker-compose up

Then the error happens:

    > node-rest-auth@ start /home/app/library
> node server.js

/home/app/library/node_modules/bindings/bindings.js:83
        throw e
        ^

Error: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version 'GLIBCXX_3.4.21' not found (required by /home/app/library/node_modules/bcrypt/build/Release/bcrypt_lib.node)
    at Object.Module._extensions..node (module.js:689:18)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at bindings (/home/app/library/node_modules/bindings/bindings.js:76:44)
    at Object.<anonymous> (/home/app/library/node_modules/bcrypt/bcrypt.js:3:35)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/app/library/app/models/user.js:3:16)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-rest-auth@ start: 'node server.js'
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-rest-auth@ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/app/.npm/_logs/2018-02-05T16_21_54_845Z-debug.log
    
asked by anonymous 05.02.2018 / 20:35

1 answer

1

After much trying to fix such an error

Error is actually quite simple. By doing COPY . $HOME/library and running docker build . we send < node_modules together . This causes the settings of npm install to actually personal machine .

There is a simple way to work around what is creating (or adding node_modules if you already have such a file) a .dockerignore where we < %, thus:

.dockerignore

node_modules

This should fix the problem.

Clear caches, or delete all images (which is what I did), and then run node_modules or docker build . again, and error will no longer be there.

    
06.02.2018 / 17:14