“无法加载gRPC二进制模块”。在Docker容器中运行Sails.js应用程序时出错 [英] "Failed to load gRPC binary module" error when running a Sails.js application inside a Docker container

查看:171
本文介绍了“无法加载gRPC二进制模块”。在Docker容器中运行Sails.js应用程序时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地Docker开发人员环境来构建Sails.js应用程序。这是我的Dockerfile的样子:

I have a local Docker developer environment to build a Sails.js application. This is what my Dockerfile looks like:

FROM node:8.12
LABEL Name=us.gcr.io/my-project/my-app Version=1.0.0

# Container configuration
RUN npm install -g sails@1.0.2 grunt@1.0.3 nodemon@1.18.4
WORKDIR /usr/src/app
COPY ./server/package.json ./package.json
RUN npm install
VOLUME /usr/src/app
EXPOSE 1337

这是我的docker-compose.yml文件的样子:

This is what my docker-compose.yml file looks like:

version: '3.4'

services:
  server:
    image: us.gcr.io/my-project/my-app:latest
    build: .
    environment:
      NODE_ENV: development
      IS_DEV_MACHINE: "yes"
    ports:
      - 1338:1337 # HOST_PORT is 1339 to avoid conflicts with other Sails.js apps running on host
    volumes:
      - ./server:/usr/src/app
    entrypoint: nodemon

  mongodb:
    image: mongo:4
    ports:
      - 27018:27017 # HOST_PORT is 27018 to avoid conflicts with other MongoDB databases running on host
    volumes:
      - ../database:/data/db

通常情况下,一切正常,但是我最近导入并初始化了 @ google-cloud / logging 应用程序中的NPM包,现在,当我运行 docker-compose时 c ,出现以下错误:

Normally, everything works fine however, I recently imported and initialised the @google-cloud/logging NPM package in my application and now, when I run docker-compose up, I get the following error:

server_1   | error: Bootstrap encountered an error: (see below)
server_1   | error: Failed to lift app: { Error: Failed to load gRPC binary module because it was not installed for the current system
server_1   | Expected directory: node-v57-linux-x64-musl
server_1   | Found: [node-v57-darwin-x64-unknown]
server_1   | This problem can often be fixed by running "npm rebuild" on the current system
server_1   | Original error: Cannot find module '/usr/src/app/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-musl/grpc_node.node'
server_1   |     at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/grpc_extension.js:53:17)
server_1   |     at Module._compile (module.js:653:30)
server_1   |     at Object.Module._extensions..js (module.js:664:10)
server_1   |     at Module.load (module.js:566:32)
server_1   |     at tryModuleLoad (module.js:506:12)
server_1   |     at Function.Module._load (module.js:498:3)
server_1   |     at Module.require (module.js:597:17)
server_1   |     at require (internal/module.js:11:18)
server_1   |     at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/client_interceptors.js:145:12)
server_1   |     at Module._compile (module.js:653:30)
server_1   |     at Object.Module._extensions..js (module.js:664:10)
server_1   |     at Module.load (module.js:566:32)
server_1   |     at tryModuleLoad (module.js:506:12)
server_1   |     at Function.Module._load (module.js:498:3)
server_1   |     at Module.require (module.js:597:17)
server_1   |     at require (internal/module.js:11:18) code: 'MODULE_NOT_FOUND' }
mongodb_1  | 2018-10-09T09:27:52.521+0000 I NETWORK  [conn4] end connection 172.19.0.2:48730 (0 connections now open)

在上面的错误中, Bootstrap是我的Sails.js项目中的bootstrap.js文件,用于初始化@ google-cloud / logging。这是我在bootstrap.js中初始化记录器的方式:

In the error above, "Bootstrap" is the bootstrap.js file in my Sails.js project that initialises @google-cloud/logging. This is how I am initialising the logger in bootstrap.js:

// Globally required packages
const { Logging } = require('@google-cloud/logging');
const logging = new Logging({ projectId: 'my-project' });
const logger = logging.log('test');

我似乎无法弄清楚为什么会发生此错误。我什至尝试将基本的Docker映像更改为正式的Google App Engine Docker映像(gcr.io/google-appengine/nodejs),但这也无济于事。我在任何地方都找不到解决此问题的方法。感谢任何帮助。

I just can't seem to figure out why this error is occurring. I even tried changing my base Docker image to the official Google App Engine Docker image (gcr.io/google-appengine/nodejs) and that did not help either. i can't find any solutions to this problem anywhere. Appreciate any help.

推荐答案

如果有可能,您进行了 npm安装应该在本地Mac( darwin )环境中何时在容器( linux )中完成? grpc二进制文件用于错误的OS,因此错误。

By any chance did you do a npm install on your local Mac (darwin) environment when it should have been done in the container (linux)? The grpc binary is for the wrong OS thus the error. This often happens with a local Mac running a linux Docker container.


预期目录:node-v57-linux-x64-musl这通常在运行Linux Docker容器的本地Mac上发生。找到
:[node-v57-darwin-x64-unknown]

解决方法是将 rm -fr node_modules 并在容器中进行 npm安装

The solution would be to rm -fr node_modules and do npm install in the container.

这篇关于“无法加载gRPC二进制模块”。在Docker容器中运行Sails.js应用程序时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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