Dockerfile:如何在Node Alpine镜像上正确安装bcrypt?

3

我写了一个Dockerfile,基于node:10.13镜像创建了一个nodeJS应用程序。该应用程序需要使用bcrypt。目前完整的node镜像运行良好。但是显然结果太大,因此我尝试使用node:10.13-alpine镜像。因此,我将Dockerfile更改为以下内容:

FROM node:10.13-alpine
RUN apk --no-cache add --virtual \
      builds-deps \
      build-base \
      python

WORKDIR /home/node/app

COPY ./package*.json ./
COPY ./.babelrc ./

RUN npm set progress=false \
    && npm config set depth 0 \
    && npm install --only=production --silent \
    && cp -R node_modules prod_node_modules \
    && npm install --silent \
    && apk del builds-deps

但是这给了我一些错误。我的Dockerfile缺少什么?当然,我希望得到一个小的结果镜像...
Step 7/7 : RUN npm set progress=false && npm config set depth 0 && npm install --only=production --silent && cp -R node_modules prod_node_modules && npm install --silent
 ---> Running in 3eadd8526173
make: Entering directory '/home/node/app/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_new.h:189:0,
                 from ../../nan/nan.h:222,
                 from ../src/bcrypt_node.cc:1:
../../nan/nan_implementation_12_inl.h: In static member function 'static Nan::imp::FactoryBase<v8::StringObject>::return_t Nan::imp::Factory<v8::StringObject>::New(v8::Local<v8::String>)':
../../nan/nan_implementation_12_inl.h:340:37: warning: 'static v8::Local<v8::Value> v8::StringObject::New(v8::Local<v8::String>)' is deprecated: Use Isolate* version [-Wdeprecated-declarations]
   return v8::StringObject::New(value).As<v8::StringObject>();
                                     ^
In file included from /root/.node-gyp/10.13.0/include/node/v8.h:26:0,
                 from /root/.node-gyp/10.13.0/include/node/node.h:63,
                 from ../../nan/nan.h:52,
                 from ../src/bcrypt_node.cc:1:
/root/.node-gyp/10.13.0/include/node/v8.h:5053:37: note: declared here
                 static Local<Value> New(Local<String> value));
                                     ^
/root/.node-gyp/10.13.0/include/node/v8config.h:324:3: note: in definition of macro 'V8_DEPRECATED'
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
In file included from ../src/bcrypt_node.cc:1:0:
../../nan/nan.h: In constructor 'Nan::Utf8String::Utf8String(v8::Local<v8::Value>)':
../../nan/nan.h:1066:53: warning: 'v8::Local<v8::String> v8::Value::ToString() const' is deprecated: Use maybe version [-Wdeprecated-declarations]
       v8::Local<v8::String> string = from->ToString();
                                                     ^
In file included from /root/.node-gyp/10.13.0/include/node/node.h:63:0,
                 from ../../nan/nan.h:52,
                 from ../src/bcrypt_node.cc:1:
/root/.node-gyp/10.13.0/include/node/v8.h:10040:15: note: declared here
 Local<String> Value::ToString() const {
               ^~~~~
In file included from ../src/bcrypt_node.cc:1:0:
../../nan/nan.h:1080:74: warning: 'int v8::String::WriteUtf8(char*, int, int*, int) const' is deprecated: Use Isolate* version [-Wdeprecated-declarations]
         length_ = string->WriteUtf8(str_, static_cast<int>(len), 0, flags);
                                                                          ^
In file included from /root/.node-gyp/10.13.0/include/node/v8.h:26:0,
                 from /root/.node-gyp/10.13.0/include/node/node.h:63,
                 from ../../nan/nan.h:52,
                 from ../src/bcrypt_node.cc:1:
/root/.node-gyp/10.13.0/include/node/v8.h:2659:21: note: declared here
                 int WriteUtf8(char* buffer, int length = -1,
                     ^
/root/.node-gyp/10.13.0/include/node/v8config.h:324:3: note: in definition of macro 'V8_DEPRECATED'
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../src/bcrypt_node.cc: In function 'char {anonymous}::ToCharVersion(v8::Local<v8::String>)':
../src/bcrypt_node.cc:66:30: warning: 'v8::String::Utf8Value::Utf8Value(v8::Local<v8::Value>)' is deprecated: Use Isolate version [-Wdeprecated-declarations]
   String::Utf8Value value(str);
                              ^
In file included from /root/.node-gyp/10.13.0/include/node/v8.h:26:0,
                 from /root/.node-gyp/10.13.0/include/node/node.h:63,
                 from ../../nan/nan.h:52,
                 from ../src/bcrypt_node.cc:1:
/root/.node-gyp/10.13.0/include/node/v8.h:2892:28: note: declared here
                   explicit Utf8Value(Local<v8::Value> obj));
                            ^
/root/.node-gyp/10.13.0/include/node/v8config.h:324:3: note: in definition of macro 'V8_DEPRECATED'
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../src/bcrypt_node.cc: In function 'Nan::NAN_METHOD_RETURN_TYPE {anonymous}::GenerateSalt(Nan::NAN_METHOD_ARGS_TYPE)':
../src/bcrypt_node.cc:121:60: warning: 'v8::Local<v8::String> v8::Value::ToString() const' is deprecated: Use maybe version [-Wdeprecated-declarations]
     const char minor_ver = ToCharVersion(info[0]->ToString());
                                                            ^
In file included from /root/.node-gyp/10.13.0/include/node/node.h:63:0,
                 from ../../nan/nan.h:52,
                 from ../src/bcrypt_node.cc:1:
/root/.node-gyp/10.13.0/include/node/v8.h:10040:15: note: declared here
 Local<String> Value::ToString() const {
               ^~~~~

  // ... repeated above message

  SOLINK_MODULE(target) Release/obj.target/bcrypt_lib.node
  COPY Release/bcrypt_lib.node
  COPY /home/node/app/node_modules/bcrypt/lib/binding/bcrypt_lib.node
  TOUCH Release/obj.target/action_after_build.stamp
make: Leaving directory '/home/node/app/node_modules/bcrypt/build'

它真的失败了吗?如果你添加Dockerfile中将应用程序复制进去并声明一个CMD以启动它,那么它会运行吗? - David Maze
@DavidMaze 是的,它可以运行。但是那些日志是什么意思?我不应该避免它们吗? - user3142695
1个回答

3

bcrypt在Alpine上没有预装,因此npm会从源代码构建它。

您看到的是来自gcc(C++编译器)的构建警告,特别是5个deprecated-declarations警告:

 warning: 'v8::Local<v8::String> v8::Value::ToString() const' is deprecated: Use maybe version [-Wdeprecated-declarations]

这些警告可能是无害的:它们表示使用了带有deprecated函数属性标记的函数。这更多地是对bcrypt维护人员的问题,您可以安全地忽略它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接