在Docker容器中使用bcrypt的ELF头或安装问题 [英] ELF Header or installation issue with bcrypt in Docker container

查看:186
本文介绍了在Docker容器中使用bcrypt的ELF头或安装问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个longshot的种类,但有人在linux容器(特别是docker)中使用bcrypt有任何问题,并且知道自动解决方法?我有两个相同的问题:

Kind of a longshot, but has anyone had any problems using bcrypt in a linux container (specifically docker) and know of an automated workaround? I have the same issue as these two:

AWSBox上带有节点bcrypt的ELF头无效

运行节点应用程序时bcrypt无效的elf标头

我的Dockerfile

# Pull base image
FROM node:0.12

# Expose port 8080
EXPOSE 8080

# Add current directory into path /data in image
ADD . /data

# Set working directory to /data
WORKDIR /data

# Install dependencies from package.json
RUN npm install --production

# Run index.js
CMD ["npm", "start"]

如果我已经在我的node_modules中安装了bcrypt,我得到了前面提到的无效的ELF头错误,但是如果我删除它(或者只是自己或所有的包),那么当我建立容器我必须在构建后手动输入容器并将其安装在其中。

I get the previously mentioned invalid ELF header error if I have bcrypt already installed in my node_modules, but if I remove it (either just itself or all my packages), it isn't installed for some reason when I build the container. I have to manually enter the container after the build and install it inside.

有自动解决方法吗?

或者也许,只是,bcrypt与一个Node栈?

Or maybe, just, what would be a good alternative to bcrypt with a Node stack?

推荐答案

利亚姆的评论是在钱上,只是为了将来的旅客在互联网上扩展。

Liam's comment is on the money, just expanding on it for future travellers on the internets.

问题是您已将node_modules文件夹复制到容器中。这是一个问题的原因是bcrypt是一个本机模块。这不仅仅是javascript,而且还有一堆在安装时被编译的C代码。

The issue is that you've copied your node_modules folder into your container. The reason that this is a problem is that bcrypt is a native module. It's not just javascript, but also a bunch of C code that gets compiled at the time of installation.

从该编译中出来的二进制文件存储在node_modules文件夹中它们被定制到他们建造的地方。将他们从OSX家中移植到一个奇怪的Linux地面,导致他们行为不端,抱怨ELF头和仙女脚。

The binaries that come out of that compilation get stored in the node_modules folder and they're customised to the place they were built. Transplanting them out of their OSX home into a strange Linux land causes them to misbehave and complain about ELF headers and fairy feet.

解决方案是 echo node_modules>> .dockerignore 并运行 npm install 作为您的Dockerfile的一部分。这意味着本机模块将在容器内编译,而不是在笔记本电脑上。

The solution is to echo node_modules >> .dockerignore and run npm install as part of your Dockerfile. This means that the native modules will be compiled inside the container rather than outside it on your laptop.

有了这个,没有在启动CMD之前,需要运行npm安装。只要在Dockerfile的构建阶段就可以了。

With this in place, there is no need to run npm install before your start CMD. Just having it in the build phase of the Dockerfile is fine.

protip:官方节点图像设置NODE_ENV =默认生成,其中npm对应于 - 生产标志。大多数时候这是一件好事。当您的Dockerfile还包含依赖于dev依赖关系(webpack等)的一些构建步骤时,这不是一件好事。在这种情况下,您需要 NODE_ENV = null npm install

protip: the official node images set NODE_ENV=production by default, which npm treats the same as the --production flag. Most of the time this is a good thing. It is not a good thing when your Dockerfile also contains some build steps that rely on dev dependencies (webpack, etc). In that case you want NODE_ENV=null npm install

pro protip:您可以更好地利用Docker的缓存将您的package.json分别复制到您的其余代码。使您的Docker文件如下所示:

pro protip: you can take better advantage of Docker's caching by copying in your package.json separately to the rest of your code. Make your Dockerfile look like this:

# Pull base image
FROM node:0.12

# Expose port 8080
EXPOSE 8080

# Set working directory to /data
WORKDIR /data

# Set working directory to /data
COPY package.json /data

# Install dependencies from package.json
RUN npm install

# Add current directory into path /data in image
ADD . /data

# Run index.js
CMD npm start

而且,当您更改package.json时,Docker只会重新运行 npm install ,而不是每次更改一行代码。

And that way Docker will only re-run npm install when you change your package.json, not every time you change a line of code.

这篇关于在Docker容器中使用bcrypt的ELF头或安装问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆