Alpine linux in Docker container => `env: can't execute 'node': No such file or directory`

21.6k views Asked by At

I am installing Node.js version 8 in an Alpine linux container like so:

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 and /usr/local/bin/npm exist, and npm somehow is indeed recognized at the command line. But for the node executable, I get this error:

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

I can confirm that the $PATH variable includes both

/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'

so why can't env find the node executable? So weird.

Here is a clue:

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

after running this new call:

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

I still get an error:

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

There are 2 answers

3
Phil E On BEST ANSWER

The Alpine distro is based on a libc variant called musl-libc. The node binary you are installing is compiled against glibc, as most (all?) other standard distros use the more commonly used glibc standard library.

One option is to add glibc to your alpine distro base, and then if you were truly unable to compile node against musl-libc you could allow the glibc support you added handle the mismatch. There are other stackoverflow answers which provide details on how to do this.

However, I think the best case scenario is for you to use a node binary built against Alpine's musl-libc. This is the way the official node images handle the alpine tag variant. You can see how they do that here in the official Node 12.4.0 release Dockerfile for node's alpine variant. Of course your build will be longer to build node versus download a pre-built binary, but it will simplify any complications around trying to shoehorn glibc support into Alpine.

6
VonC On

Check if there is no missing dependencies that might be missing for node to execute: add an ldd /usr/local/bin/node

It could be the case the base (Alpine) image used has some dependencies missing for node to work: you can test if the issue persists when you change said base image (with an ubuntu one for instance)

The fact that ldd mentions missing dynamic libraries/symbols explains the error message.

See how node is built from its Dockerfile:

FROM buildpack-deps:jessie

Ie: it installs on top of a much complete image than an alpine one.

It would be easier to use the node image directly, and build from it.