My Node Dockfile
:
# Set the base image to ubuntu
FROM ubuntu
# Define working directory
ADD . /src
WORKDIR /src
# Install Node.js & other
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.
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.
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.
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)
And now when you will build your container, it will build everything as per container's OS.
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/
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.