Bcrypt installation fails in Docker

I’ve created a Node-application with MongoDB that runs in Docker. It worked fine until I included node.bcrypt.js. This makes Node crash with node-gyp and bcrypt.

The app runs fine locally and on Heroku.

  • docker invalid characters for local volume name
  • Deploying Java app to Docker image
  • android.test did not get installed. Reason: 'Aborted '
  • docker: “commit” requires a maximum of 2 arguments
  • Files generated through docker-compose run web rails g controller do not have permissions to edit
  • Move docker data volume containers between CoreOS hosts
  • I tried to install a few suggested packages that I found online, that were known to be needed based on error messages. This is why I’ve added a few extra dependencies, see the node-gyp-related line in the dockerfile below.

    Now it’s gotten where I cannot find any more suggestions, but it still doens’t work. I feel it’s weird that it works both locally and on Heorku, but not on Docker, and therefore that it’s something I’m missing.

    Thanks in advance.

    Error:

    > crowdshelf-server@1.0.0 start /server
    > node index.js
    
      COPY Release/bcrypt_lib.node
    make: Leaving directory `/server/node_modules/bcrypt/build'
    module.js:338
        throw err;
              ^
    Error: Cannot find module './lib/topologies/server'
        at Function.Module._resolveFilename (module.js:336:15)
        at Function.Module._load (module.js:278:25)
        at Module.require (module.js:365:17)
        at require (module.js:384:17)
        at Object.<anonymous> (/server/node_modules/mongodb/node_modules/mongodb-core/index.js:3:13)
        at Module._compile (module.js:460:26)
        at Object.Module._extensions..js (module.js:478:10)
        at Module.load (module.js:355:32)
        at Function.Module._load (module.js:310:12)
        at Module.require (module.js:365:17)
        at require (module.js:384:17)
    
    npm ERR! Linux 3.13.0-58-generic
    npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
    npm ERR! node v0.12.7
    npm ERR! npm  v2.11.3
    npm ERR! code ELIFECYCLE
    npm ERR! crowdshelf-server@1.0.0 start: `node index.js`
    npm ERR! Exit status 1
    

    This is after I added a few installations to my Dockerfile, see the line after node-gyp. Dockerfile:

    # Base Docker-image on Ubuntu
    FROM    ubuntu:latest
    
    #install mongodb
    #install git, curl, python and mongo
    # node-gyp 
    RUN apt-get install -y build-essential make automake gcc g++ cpp libkrb5-dev libc6-dev man-db autoconf pkg-config 
    
    # Create the MongoDB data directory
    RUN mkdir -p /data/db
    
    # mongodb setup
    # Install NodeJS
    RUN curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -
    RUN apt-get update && apt-get install -y nodejs
    RUN npm install -g node-gyp
    
    # Git-clone project
    # expose ports
    # Install dependencies and start server and database
    CMD cd /server && sh start.sh
    

    The starth.sh-script simply installs dependencies and starts both MongoDB and server.

    EDIT:
    The repo tells me to check out the node-gyp dependencies, but I feel that’s been covered by the Dockerfile shown above.

  • Docker NodeJs for ReactJs
  • Are Dockerfiles stored on my machine?
  • Does the Docker RPM require additional dependencies?
  • Docker compose with Drone and Gitlab, Gitlab errors “The redirect URI included is not valid.”
  • Error Deploying Docker Container to Elastic Beanstalk
  • Can't to connect to postgres container
  • 2 Solutions collect form web for “Bcrypt installation fails in Docker”

    It is crashing because you are missing some essentials tool for the compilation purposes of Bcrypt. Bcrypt needs to be compiled each time you do npm install to crate a version for the operating system that is running on since it is written in C.

    For those that would like to use the original Bcrypt, you can run the following docker command:

    docker run -t -i --rm -v $(pwd):/app -w /app node:slim sh -c 'apt-get update && apt-get install -y build-essential && apt-get install -y python && npm install'
    

    Before we do npm install we need to:

    • apt-get update: make sure the package management system knows were to find what we want.
    • apt-get install -y build-essential: will install all the tools needed to compile C code and more
    • apt-get install -y python: we add python since it is needed and it is not included in the build-essential package.

    Once we have all this stuff, we can run npm install successfully 🙂

    Hope this helps.

    I solved this by simply changing the bcrypt-library. This one was created based on a similar problem, and provides the same API. The only difference from the library mentioned in my question is:

    bcrypt.hash(password, function(err, hash) {
        if(!err) callback(hash);
    });
    

    While in the one linked in this answer:

    bcrypt.hash(password, null, null, function(err, hash) { // Addd nulls
        if(!err) callback(hash);
    });
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.