Bcrypt: invalid ELF header with Docker and Sails.JS

后端 未结 7 1930
被撕碎了的回忆
被撕碎了的回忆 2021-01-02 02:41

My Node Dockfile:

# Set the base image to ubuntu
FROM ubuntu

# Define working directory
ADD . /src
WORKDIR /src

# Install Node.js & other          


        
相关标签:
7条回答
  • 2021-01-02 02:58

    I was experiencing same thing, even though using Express, not Sails. I tried every suggestion here with no success. What made the trick was change the npm module bcrypt by bcryptjs:

    npm uninstal bcrypt
    npm install bcryptjs --save
    

    Then change your require to something like

    var bcrypt   = require('bcryptjs');
    

    It is working flawlessly now.

    0 讨论(0)
  • 2021-01-02 03:01

    In my package config I had "bcrypt":"^0.8.0" and when I took out the ^ and changed it to "bcrypt":"0.8.0" I was able to get everything running.

    The issue was that it was trying to run bcrypt 0.8.5 and that was causing issues for some reason.

    0 讨论(0)
  • 2021-01-02 03:05

    just to add a new possible cause. I tried to build my docker image for a nodejs app but i've gotthe error invalid ELF header. In my case i ve resolved the issue by adding the node_modules/* from the .dockerignore file.

    0 讨论(0)
  • 2021-01-02 03:11

    The root cause is => Docker Context. Docker context is copying everything from your root folder to destination container working directory.

    So you have to add a .dockerignore file and add these entries (with any other files that you want to ignore)

    • node_modules
    • npm-debug.log

    And now when you will build your container, it will build everything as per container's OS.

    0 讨论(0)
  • 2021-01-02 03:12

    I have found that excluding the entire local node_modules directory does not allow you to install npm packages and have your docker container track those changes in the container on the fly. I will have to rebuild my container each time. To avoid this specify only the bcrypt directory in the container volume and allow docker to track changes when other packages are installed or removed:

    volumes: 
      - .:/app
      - /app/node_modules/bcrypt/
    
    0 讨论(0)
  • 2021-01-02 03:12

    There is a simple way that allowed me to solve this problem, I think this can helps you also in Docker, just add to the run instructions on you docker file this instructions

    1. Uninstall bcrypt

    npm uninstall bcrypt
    

    2.- Install bcrypt again

    npm i bcrypt
    

    Edit this part of your docker file adding the lines

    ADD package.json /src/package.json
    RUN cd /src && npm install
    
    
    #Solve the problem reinstaling bcrypt
    RUN npm uninstall bcrypt
    RUN npm i bcrypt
    
    
    # Expose port
    EXPOSE  8080
    

    The error occurs because when you install bcypt, npm installs the recommended version for your machine and operating system, but when you are on another machine, this doesn't work.

    0 讨论(0)
提交回复
热议问题