Dockerfile - RUN无法在环境PATH中执行二进制文件

时间:2017-12-01 13:20:19

标签: docker dockerfile

创建dockerfile以安装依赖项二进制文件:

FROM alpine

RUN apk update \                                                                                                                                                                                                                        
    && apk add ca-certificates wget \                                                                                                                                                                                                      
    && update-ca-certificates 

RUN mkdir -p /opt/nodejs \
    && cd /opt/nodejs  \
    && wget -qO- https://nodejs.org/dist/v8.9.1/node-v8.9.1-linux-x64.tar.gz | tar xvz --strip-components=1

RUN chmod +x /opt/nodejs/bin/*

ENV PATH="/opt/nodejs/bin:${PATH}"

RUN which node
RUN node --version

which node正确识别$PATH中的节点二进制文件,因为$PATH之前的ENV命令修改了RUN node --version。但是,Step 11 : ENV PATH "/opt/nodejs/bin:${PATH}" ---> Using cache ---> 7dc04c05007f Step 12 : RUN which node ---> Running in deeaf8e9fe09 /opt/nodejs/bin/node ---> 074820b1b9b5 Step 13 : RUN node --version ---> Running in 6f7eabd95e90 /bin/sh: node: not found The command '/bin/sh -c node --version' returned a non-zero code: 127 无法找到二进制文件。

图像构建日志显示:

/bin

在映像构建过程中调用已安装二进制文件的正确方法是什么?

注意:

  1. 我也尝试将二进制文件链接到sh,但RUN仍然无法在import torch import torch.nn as nn from torch.autograd import Variable time_steps = 15 batch_size = 3 embeddings_size = 100 num_classes = 2 model = nn.LSTM(embeddings_size, num_classes) input_seq = Variable(torch.randn(time_steps, batch_size, embeddings_size)) lstm_out, _ = model(input_seq) last_out = lstm_out[-1] print(last_out) loss = nn.BCELoss() target = Variable(torch.LongTensor(batch_size).random_(0, num_classes)) print(target) err = loss(last_out.long(), target) err.backward() 中找到它们。
  2. Docker版本1.12.1

1 个答案:

答案 0 :(得分:1)

您安装的节点版本依赖于未包含在高山基本映像中的库。它也可能与glibc而不是musl相关联。

/ # apk add file
(1/2) Installing libmagic (5.28-r0)
(2/2) Installing file (5.28-r0)
Executing busybox-1.25.1-r0.trigger
OK: 9 MiB in 15 packages
/ # file /opt/nodejs/bin/node
/opt/nodejs/bin/node: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.18, BuildID[sha1]=862ecb804ed99547c06d5bd4ac1090da500acb61, not stripped
/ # ldd /opt/nodejs/bin/node
        /lib64/ld-linux-x86-64.so.2 (0x7f793665d000)
        libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f793665d000)
        librt.so.1 => /lib64/ld-linux-x86-64.so.2 (0x7f793665d000)
Error loading shared library libstdc++.so.6: No such file or directory (needed by /opt/nodejs/bin/node)
        libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f793665d000)
Error loading shared library libgcc_s.so.1: No such file or directory (needed by /opt/nodejs/bin/node)
        libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f793665d000)
        libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f793665d000)

你可以找到一个在Alpine from the docker hub official repo上安装节点的Dockerfile,这将是一个更好的起点。