Docker容器中的Alpine linux => `env:无法执行'node':没有这样的文件或目录`

时间:2017-08-31 04:57:33

标签: node.js docker alpine

我在一个Alpine linux容器中安装Node.js版本8,如下所示:

RUN apk add --no-cache wget

RUN wget http://nodejs.org/dist/v8.1.1/node-v8.1.1-linux-x64.tar.gz
RUN sudo tar -C /usr/local --strip-components 1 -xzf node-v8.1.1-linux-x64.tar.gz

RUN ls -l /usr/local/bin/node
RUN ls -l /usr/local/bin/npm

RUN ln -s /usr/local/bin/node /usr/bin/node
RUN ln -s /usr/local/bin/npm /usr/bin/npm

ENV PATH "/usr/local/bin:${PATH}"
RUN echo "PATH env variable => '$PATH'"
存在

/usr/local/bin/node/usr/local/bin/npm,并且在某种程度上确实在命令行中识别了npm。但对于节点可执行文件,我收到此错误:

Step 23/53 : RUN npm cache clean -f
 ---> Running in 8bbc96b88935
env: can't execute 'node': No such file or directory

我可以确认$ PATH变量包含两者

/usr/local/bin
/usr/bin

e.g:

Step 19/53 : RUN echo "PATH env variable => '$PATH'"
 ---> Running in c5227e6e3db0
PATH env variable => '/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

那为什么env找不到节点可执行文件呢?太奇怪了。

这是一条线索:

Step 10/52 : RUN ldd /usr/local/bin/node
 ---> Running in db210653f0ed
        /lib64/ld-linux-x86-64.so.2 (0x7fefae36b000)
        libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7fefae36b000)
        librt.so.1 => /lib64/ld-linux-x86-64.so.2 (0x7fefae36b000)
        libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fefae36b000)
        libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7fefae36b000)
        libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fefae36b000)
Error loading shared library libstdc++.so.6: No such file or directory (needed by /usr/local/bin/node)
Error loading shared library libgcc_s.so.1: No such file or directory (needed by /usr/local/bin/node)
Error relocating /usr/local/bin/node: _ZNSt15basic_streambufIcSt11char_traitsIcEE9pbackfailEi: symbol not found
Error relocating /usr/local/bin/node: _ZNSt13runtime_errorC2ERKSs: symbol not found
Error relocating /usr/local/bin/node: _ZSt19__throw_logic_errorPKc: symbol not found
Error relocating /usr/local/bin/node: _ZNSt9exceptionD2Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSsC1ERKSs: symbol not found
Error relocating /usr/local/bin/node: _ZSt17__throw_bad_allocv: symbol not found
Error relocating /usr/local/bin/node: _ZNSs6appendEmc: symbol not found
Error relocating /usr/local/bin/node: _ZNSt15basic_streambufIcSt11char_traitsIcEE6xsgetnEPcl: symbol not found
Error relocating /usr/local/bin/node: _ZNSo9_M_insertIyEERSoT_: symbol not found
Error relocating /usr/local/bin/node: _ZNSt18basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSt19basic_ostringstreamIcSt11char_traitsIcESaIcEED1Ev: symbol not found
Error relocating /usr/local/bin/node: _Znwm: symbol not found
Error relocating /usr/local/bin/node: _ZNSt11logic_errorC2ERKSs: symbol not found
Error relocating /usr/local/bin/node: _ZNSt15basic_streambufIcSt11char_traitsIcEE5imbueERKSt6locale: symbol not found
Error relocating /usr/local/bin/node: _ZNSs6assignEPKc: symbol not found
Error relocating /usr/local/bin/node: _ZTv0_n24_NSoD1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSt13basic_filebufIcSt11char_traitsIcEE5closeEv: symbol not found
Error relocating /usr/local/bin/node: _ZNKSt13runtime_error4whatEv: symbol not found
Error relocating /usr/local/bin/node: _ZTv0_n24_NSt14basic_ofstreamIcSt11char_traitsIcEED0Ev: symbol not found
Error relocating /usr/local/bin/node: __isinf: symbol not found
Error relocating /usr/local/bin/node: __cxa_demangle: symbol not found
Error relocating /usr/local/bin/node: _ZNSs9push_backEc: symbol not found
Error relocating /usr/local/bin/node: _ZNSt9basic_iosIcSt11char_traitsIcEE7copyfmtERKS2_: symbol not found
Error relocating /usr/local/bin/node: _ZNSolsEi: symbol not found
Error relocating /usr/local/bin/node: _ZSt16__throw_bad_castv: symbol not found
Error relocating /usr/local/bin/node: __cxa_guard_acquire: symbol not found
Error relocating /usr/local/bin/node: _ZNKSs4findEcm: symbol not found
Error relocating /usr/local/bin/node: _ZNSt9basic_iosIcSt11char_traitsIcEE4initEPSt15basic_streambufIcS1_E: symbol not found
Error relocating /usr/local/bin/node: _ZSt7getlineIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RSbIS4_S5_T1_ES4_: symbol not found
Error relocating /usr/local/bin/node: _ZdaPv: symbol not found
Error relocating /usr/local/bin/node: _ZNSo9_M_insertIlEERSoT_: symbol not found
Error relocating /usr/local/bin/node: __cxa_allocate_exception: symbol not found
Error relocating /usr/local/bin/node: backtrace_symbols: symbol not found
Error relocating /usr/local/bin/node: _ZNSo9_M_insertIbEERSoT_: symbol not found
Error relocating /usr/local/bin/node: _ZNSs6resizeEmc: symbol not found
Error relocating /usr/local/bin/node: _ZNSt15__exception_ptr13exception_ptrC1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSt13runtime_errorD2Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNKSt14error_category10equivalentERKSt10error_codei: symbol not found
Error relocating /usr/local/bin/node: _ZNSs12_M_leak_hardEv: symbol not found
Error relocating /usr/local/bin/node: _ZNKSs17find_first_not_ofEPKcmm: symbol not found
Error relocating /usr/local/bin/node: _Znam: symbol not found
Error relocating /usr/local/bin/node: _ZNSo9_M_insertIPKvEERSoT_: symbol not found
Error relocating /usr/local/bin/node: _ZNKSt5ctypeIcE13_M_widen_initEv: symbol not found
Error relocating /usr/local/bin/node: _ZSt18_Rb_tree_decrementPSt18_Rb_tree_node_base: symbol not found
Error relocating /usr/local/bin/node: _ZNSo5writeEPKcl: symbol not found
Error relocating /usr/local/bin/node: _ZNSo5flushEv: symbol not found
Error relocating /usr/local/bin/node: _ZNSo9_M_insertImEERSoT_: symbol not found
Error relocating /usr/local/bin/node: _ZNSt12__basic_fileIcED1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZTv0_n24_NSoD0Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNKSt15basic_stringbufIcSt11char_traitsIcESaIcEE3strEv: symbol not found
Error relocating /usr/local/bin/node: _ZNSsC1EPKcmRKSaIcE: symbol not found
Error relocating /usr/local/bin/node: _ZdlPv: symbol not found
Error relocating /usr/local/bin/node: _ZNSo3putEc: symbol not found
Error relocating /usr/local/bin/node: _ZNSt15basic_streambufIcSt11char_traitsIcEE7seekoffElSt12_Ios_SeekdirSt13_Ios_Openmode: symbol not found
Error relocating /usr/local/bin/node: _ZTv0_n24_NSt14basic_ofstreamIcSt11char_traitsIcEED1Ev: symbol not found
Error relocating /usr/local/bin/node: __cxa_guard_release: symbol not found
Error relocating /usr/local/bin/node: _ZNSs9_M_mutateEmmm: symbol not found
Error relocating /usr/local/bin/node: _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc: symbol not found
Error relocating /usr/local/bin/node: _ZNSt19basic_ostringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode: symbol not found
Error relocating /usr/local/bin/node: _ZNKSs5rfindEcm: symbol not found
Error relocating /usr/local/bin/node: _ZNSt15basic_streambufIcSt11char_traitsIcEE7seekposESt4fposI11__mbstate_tESt13_Ios_Openmode: symbol not found
Error relocating /usr/local/bin/node: _ZNSs6appendEPKcm: symbol not found
Error relocating /usr/local/bin/node: __gxx_personality_v0: symbol not found
Error relocating /usr/local/bin/node: _ZNSs4swapERSs: symbol not found
Error relocating /usr/local/bin/node: _ZNSoD0Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSsC1EmcRKSaIcE: symbol not found
Error relocating /usr/local/bin/node: _ZSt20__throw_length_errorPKc: symbol not found
Error relocating /usr/local/bin/node: _ZSt20__throw_out_of_rangePKc: symbol not found
Error relocating /usr/local/bin/node: __cxa_throw: symbol not found
Error relocating /usr/local/bin/node: _ZNSt11logic_errorD2Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSt15basic_stringbufIcSt11char_traitsIcESaIcEE7_M_syncEPcmm: symbol not found
Error relocating /usr/local/bin/node: _Unwind_Resume: symbol not found
Error relocating /usr/local/bin/node: __popcountdi2: symbol not found
Error relocating /usr/local/bin/node: _ZNSt8ios_base4InitD1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSs6appendEPKc: symbol not found
Error relocating /usr/local/bin/node: _ZNSt9basic_iosIcSt11char_traitsIcEE5rdbufEPSt15basic_streambufIcS1_E: symbol not found
Error relocating /usr/local/bin/node: __register_atfork: symbol not found
Error relocating /usr/local/bin/node: __isnan: symbol not found
Error relocating /usr/local/bin/node: _ZNKSt14error_category23default_error_conditionEi: symbol not found
Error relocating /usr/local/bin/node: _ZNSt15basic_streambufIcSt11char_traitsIcEE9showmanycEv: symbol not found
Error relocating /usr/local/bin/node: _ZNSt18condition_variableD1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSs4_Rep9_S_createEmmRKSaIcE: symbol not found
Error relocating /usr/local/bin/node: _ZNSs14_M_replace_auxEmmmc: symbol not found
Error relocating /usr/local/bin/node: _ZNSt8ios_baseD2Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSs6insertEmPKcm: symbol not found
Error relocating /usr/local/bin/node: _ZSt21__throw_runtime_errorPKc: symbol not found
Error relocating /usr/local/bin/node: _ZNSo9_M_insertIdEERSoT_: symbol not found
Error relocating /usr/local/bin/node: _ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSt6localeC1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSs6assignEPKcm: symbol not found
Error relocating /usr/local/bin/node: _ZNSs4_Rep10_M_disposeERKSaIcE: symbol not found
Error relocating /usr/local/bin/node: _ZNSs6assignERKSs: symbol not found
Error relocating /usr/local/bin/node: _ZNSs6appendERKSs: symbol not found
Error relocating /usr/local/bin/node: _ZNSt13basic_filebufIcSt11char_traitsIcEEC1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSt18basic_stringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode: symbol not found
Error relocating /usr/local/bin/node: _ZNKSs4findEPKcmm: symbol not found
Error relocating /usr/local/bin/node: _ZSt28_Rb_tree_rebalance_for_erasePSt18_Rb_tree_node_baseRS_: symbol not found
Error relocating /usr/local/bin/node: _ZNSt15basic_streambufIcSt11char_traitsIcEE9underflowEv: symbol not found
Error relocating /usr/local/bin/node: __cxa_free_exception: symbol not found
Error relocating /usr/local/bin/node: _ZSt18_Rb_tree_incrementPKSt18_Rb_tree_node_base: symbol not found
Error relocating /usr/local/bin/node: _ZNSt15__exception_ptr13exception_ptrD1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSoD1Ev: symbol not found
Error relocating /usr/local/bin/node: __cxa_pure_virtual: symbol not found
Error relocating /usr/local/bin/node: _ZNSt14basic_ofstreamIcSt11char_traitsIcEED0Ev: symbol not found
Error relocating /usr/local/bin/node: __dynamic_cast: symbol not found
Error relocating /usr/local/bin/node: _ZNSt13basic_filebufIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode: symbol not found
Error relocating /usr/local/bin/node: _ZSt18_Rb_tree_incrementPSt18_Rb_tree_node_base: symbol not found
Error relocating /usr/local/bin/node: _ZNSs4_Rep10_M_destroyERKSaIcE: symbol not found
Error relocating /usr/local/bin/node: _ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l: symbol not found
Error relocating /usr/local/bin/node: _ZNKSt14error_category10equivalentEiRKSt15error_condition: symbol not found
Error relocating /usr/local/bin/node: _ZNSt8ios_baseC2Ev: symbol not found
Error relocating /usr/local/bin/node: _ZNSt6localeD1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_: symbol not found
Error relocating /usr/local/bin/node: _ZNSt8ios_base4InitC1Ev: symbol not found
Error relocating /usr/local/bin/node: _ZnwmRKSt9nothrow_t: symbol not found
Error relocating /usr/local/bin/node: _ZNSt15basic_streambufIcSt11char_traitsIcEE5uflowEv: symbol not found
Error relocating /usr/local/bin/node: _ZSt18_Rb_tree_decrementPKSt18_Rb_tree_node_base: symbol not found
Error relocating /usr/local/bin/node: _ZNSsC1ERKSsmm: symbol not found
Error relocating /usr/local/bin/node: _ZNKSs7compareEPKc: symbol not found
Error relocating /usr/local/bin/node: _ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_: symbol not found
Error relocating /usr/local/bin/node: _ZdlPvRKSt9nothrow_t: symbol not found
Error relocating /usr/local/bin/node: _ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate: symbol not found
Error relocating /usr/local/bin/node: _ZNSsD1Ev: symbol not found
Error relocating /usr/local/bin/node: backtrace: symbol not found
Error relocating /usr/local/bin/node: _ZNSsC1EPKcRKSaIcE: symbol not found
Error relocating /usr/local/bin/node: _ZNSt15basic_streambufIcSt11char_traitsIcEE6setbufEPcl: symbol not found
Error relocating /usr/local/bin/node: _ZNSo9_M_insertIxEERSoT_: symbol not found
Error relocating /usr/local/bin/node: _ZNSs7reserveEm: symbol not found
Error relocating /usr/local/bin/node: _ZTISt14error_category: symbol not found
Error relocating /usr/local/bin/node: _ZTISt11logic_error: symbol not found
Error relocating /usr/local/bin/node: _ZTISt9exception: symbol not found
Error relocating /usr/local/bin/node: _ZTISt13runtime_error: symbol not found
Error relocating /usr/local/bin/node: _ZNSs4_Rep20_S_empty_rep_storageE: symbol not found
Error relocating /usr/local/bin/node: _ZNSt8__detail12__prime_listE: symbol not found
Error relocating /usr/local/bin/node: _ZTVSt14error_category: symbol not found
Error relocating /usr/local/bin/node: _ZSt7nothrow: symbol not found
Error relocating /usr/local/bin/node: _ZTVSt15basic_stringbufIcSt11char_traitsIcESaIcEE: symbol not found
Error relocating /usr/local/bin/node: _ZTVN10__cxxabiv121__vmi_class_type_infoE: symbol not found
Error relocating /usr/local/bin/node: _ZTVSt19basic_ostringstreamIcSt11char_traitsIcESaIcEE: symbol not found
Error relocating /usr/local/bin/node: _ZTTSt14basic_ofstreamIcSt11char_traitsIcEE: symbol not found
Error relocating /usr/local/bin/node: _ZTVN10__cxxabiv117__class_type_infoE: symbol not found
Error relocating /usr/local/bin/node: _ZTVN10__cxxabiv120__si_class_type_infoE: symbol not found
Error relocating /usr/local/bin/node: _ZTVSt15basic_streambufIcSt11char_traitsIcEE: symbol not found
Error relocating /usr/local/bin/node: _ZTVSt14basic_ofstreamIcSt11char_traitsIcEE: symbol not found
Error relocating /usr/local/bin/node: _ZTVSt9basic_iosIcSt11char_traitsIcEE: symbol not found
Error relocating /usr/local/bin/node: _ZTVSt18basic_stringstreamIcSt11char_traitsIcESaIcEE: symbol not found
Error relocating /usr/local/bin/node: _ZTVSt13basic_filebufIcSt11char_traitsIcEE: symbol not found
Error relocating /usr/local/bin/node: _ZTTSt18basic_stringstreamIcSt11char_traitsIcESaIcEE: symbol not found
Error relocating /usr/local/bin/node: _ZTTSt19basic_ostringstreamIcSt11char_traitsIcESaIcEE: symbol not found
The command '/bin/sh -c ldd /usr/local/bin/node' returned a non-zero code: 127
运行这个新电话后

RUN apk add --no-cache libstdc++ && apk add --no-cache libgcc

我仍然收到错误:

Step 12/54 : RUN ldd /usr/local/bin/node
 ---> Running in deecef947d0b
        /lib64/ld-linux-x86-64.so.2 (0x7f9266dee000)
        libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f9266dee000)
        librt.so.1 => /lib64/ld-linux-x86-64.so.2 (0x7f9266dee000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f9266a9c000)
        libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f9266dee000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f926688a000)
        libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f9266dee000)
        libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f9266dee000)
Error relocating /usr/local/bin/node: __isinf: symbol not found
Error relocating /usr/local/bin/node: backtrace_symbols: symbol not found
Error relocating /usr/local/bin/node: __register_atfork: symbol not found
Error relocating /usr/local/bin/node: __isnan: symbol not found
Error relocating /usr/local/bin/node: backtrace: symbol not found

2 个答案:

答案 0 :(得分:6)

Alpine发行版基于名为musl-libc的libc变体。您正在安装的节点二进制文件是针对 glibc 编译的,因为大多数(所有?)其他标准发行版使用更常用的 glibc 标准库。

一个选项是将glibc添加到您的alpine发行版基础中,然后如果您真的无法针对 musl-libc 编译节点,则可以允许您添加的glibc支持处理不匹配。还有其他stackoverflow answers提供了有关如何执行此操作的详细信息。

然而,我认为最好的情况是您使用针对Alpine的 musl-libc 构建的节点二进制文件。这是官方节点图像处理高山标签变体的方式。您可以在节点的高山变体的official image Dockerfile中看到他们如何做到这一点。当然,你的构建将比构建节点更长,而不是下载一个预先构建的二进制文件,但它将简化尝试将glibc支持转变为Alpine的任何复杂性。

答案 1 :(得分:1)

检查节点是否缺少可能缺少的依赖项:添加ldd /usr/local/bin/node

可能是这样的情况:所使用的基础(Alpine)图像缺少某些依赖项以便节点工作:您可以测试当您更改所述基本图像时问题是否仍然存在(例如,使用ubuntu)

ldd提到缺少动态库/符号的事实解释了错误消息。

了解如何根据its Dockerfile构建节点:

FROM buildpack-deps:jessie

即:它安装在一个完整的图像之上,而不是高山图像。

直接使用节点图像并从中构建它会更容易。