繁体   English   中英

错误:/ng-app/node_modules/bcrypt/lib/binding/bcrypt_lib.node:无效的ELF标头

[英]ERROR: /ng-app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header

我有一个使用Node.js的API项目的Dockerfile-Express.js

api.dockerfile

FROM node:8.9.4

COPY package.json ./

RUN npm set progress=false && npm config set depth 0 && npm cache clean --force

## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
RUN npm i && npm install nodemon --save \
    && npm install pm2 -g \
    && npm install -g sequelize-cli \
    && mkdir /ng-app \
    && chown -R node:node /ng-app \
    && cp -R ./node_modules ./ng-app

USER node

WORKDIR /ng-app

COPY . .
RUN mv docker.env .env

# Migration
RUN sequelize db:migrate
RUN sequelize db:seed:all

CMD ["pm2-runtime", "index.js"]

泊坞窗,compose.yaml

version: "2"
services:
  iproject-api:
    build:
      context: ./api
      dockerfile: api.dockerfile
    image: 'iproject-api'
    ports:
      - '3002:3002'
  iproject-web:
    build:
      context: ./web
      dockerfile: web.dockerfile
    image: 'iproject-web:latest'
    ports:
      - '8080:8080'
    links:
      - iproject-api

这是结果,我得到了

Building iproject-api
Step 1/11 : FROM node:9.3.0
 ---> 3d1823068e39
Step 2/11 : COPY package.json ./
 ---> 793cf321a2ce
Removing intermediate container 42ec19ebe5c0
Step 3/11 : RUN npm set progress=false && npm config set depth 0 && npm cache clean --force
 ---> Running in 86f16967a881
npm WARN using --force I sure hope you know what you are doing.
 ---> e70409fdab5a
Removing intermediate container 86f16967a881
Step 4/11 : RUN npm i && npm install nodemon --save     && npm install pm2 -g     && npm install -g sequelize-cli     && mkdir /ng-app     && chown -R node:node /ng-app     && cp -R ./node_modules ./ng-app
 ---> Running in 04532538ea1c

> bcrypt@1.0.3 install /node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v1.0.3/bcrypt_lib-v1.0.3-node-v59-linux-x64.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for bcrypt@1.0.3 and node@9.3.0 (node-v59 ABI) (falling back to source compile with node-gyp) 
make: Entering directory '/node_modules/bcrypt/build'
  CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.o
In file included from ../../nan/nan.h:192:0,
                 from ../src/bcrypt_node.cc:1:
../../nan/nan_maybe_43_inl.h: In function 'Nan::Maybe<bool> Nan::ForceSet(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Value>, v8::PropertyAttribute)':
../../nan/nan_maybe_43_inl.h:112:73: warning: 'v8::Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>, v8::PropertyAttribute)' is deprecated (declared at /root/.node-gyp/9.3.0/include/node/v8.h:3114): Use CreateDataProperty / DefineOwnProperty [-Wdeprecated-declarations]
   return obj->ForceSet(isolate->GetCurrentContext(), key, value, attribs);
                                                                         ^
  SOLINK_MODULE(target) Release/obj.target/bcrypt_lib.node
  COPY Release/bcrypt_lib.node
  COPY /node_modules/bcrypt/lib/binding/bcrypt_lib.node
  TOUCH Release/obj.target/action_after_build.stamp
make: Leaving directory '/node_modules/bcrypt/build'
npm notice created a lockfile as package-lock.json. You should commit this file.
added 259 packages in 10.214s

> nodemon@1.14.10 postinstall /node_modules/nodemon
> node -e "console.log('\u001b[32mLove nodemon? You can now support the project via the open collective:\u001b[22m\u001b[39m\n > \u001b[96m\u001b[1mhttps://opencollective.com/nodemon/donate\u001b[0m\n')" || exit 0

Love nodemon? You can now support the project via the open collective:
 > https://opencollective.com/nodemon/donate

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ nodemon@1.14.10
added 246 packages in 6.452s
/usr/local/bin/pm2 -> /usr/local/lib/node_modules/pm2/bin/pm2
/usr/local/bin/pm2-docker -> /usr/local/lib/node_modules/pm2/bin/pm2-docker
/usr/local/bin/pm2-dev -> /usr/local/lib/node_modules/pm2/bin/pm2-dev
/usr/local/bin/pm2-runtime -> /usr/local/lib/node_modules/pm2/bin/pm2-runtime
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/pm2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ pm2@2.9.1
added 251 packages in 6.019s
/usr/local/bin/sequelize -> /usr/local/lib/node_modules/sequelize-cli/lib/sequelize
+ sequelize-cli@3.2.0
added 105 packages in 3.671s
 ---> 4b47d47d16d4
Removing intermediate container 04532538ea1c
Step 5/11 : USER node
 ---> Running in 97ec9500d986
 ---> 4b9e99e1facc
Removing intermediate container 97ec9500d986
Step 6/11 : WORKDIR /ng-app
 ---> 33f8184f151a
Removing intermediate container f49ca4cea9c3
Step 7/11 : COPY . .
 ---> 1243df32a81e
Removing intermediate container 38c9727ec50b
Step 8/11 : RUN mv docker.env .env
 ---> Running in 8e168cdde98d
 ---> bb8d34bb1c7f
Removing intermediate container 8e168cdde98d
Step 9/11 : RUN sequelize db:migrate
 ---> Running in f97010013425

Sequelize CLI [Node: 9.3.0, CLI: 3.2.0, ORM: 4.31.0]

WARNING: This version of Sequelize CLI is not fully compatible with Sequelize v4. https://github.com/sequelize/cli#sequelize-support

Loaded configuration file "pg/config/config.js".
Using environment "development".
Thu, 11 Jan 2018 03:54:44 GMT sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators at ../node_modules/sequelize/lib/sequelize.js:237:13
No migrations were executed, database schema was already up to date.
 ---> 130ed294e658
Removing intermediate container f97010013425
Step 10/11 : RUN sequelize db:seed:all
 ---> Running in a2da59cc7310

Sequelize CLI [Node: 9.3.0, CLI: 3.2.0, ORM: 4.31.0]

WARNING: This version of Sequelize CLI is not fully compatible with Sequelize v4. https://github.com/sequelize/cli#sequelize-support

Loaded configuration file "pg/config/config.js".
Using environment "development".
Thu, 11 Jan 2018 03:54:47 GMT sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators at ../node_modules/sequelize/lib/sequelize.js:237:13
== 20171218103558-Permissions: migrating =======
== 20171218103558-Permissions: migrated (0.048s)

== 20171218110927-Companies: migrating =======
== 20171218110927-Companies: migrated (0.041s)

== 20171218112759-User: migrating =======

ERROR: /ng-app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header

ERROR: Service 'iproject-api' failed to build: The command '/bin/sh -c sequelize db:seed:all' returned a non-zero code: 1

这主要是猜测。 但是您的步骤7将当前上下文中的所有文件复制到/ng-app (包括您可能拥有的任何node_modules文件夹)。 如果此node_modules文件夹包含二进制文件并且它们已安装在macOS或Windows上,则它们将是容器(即Linux)的错误体系结构。

针对此特定情况的简单解决方案是通过将node_modules文件夹添加到您的.dockerignore文件( https://docs.docker.com/engine/reference/builder/#dockerignore-file )中来排除它。 这样可以防止将node_modules复制到生成的容器中,而将使用步骤4的npm install中的node_modules

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM