【问题标题】:Some RUNs won't work on docker but will when inside a container一些 RUN 无法在 docker 上运行,但在容器内时会运行
【发布时间】:2015-12-31 05:46:47
【问题描述】:

我有一个用于一些 lua 和 torch 相关任务的 Dockerfile,我正在尝试使用 luarocks 安装一些岩石。

FROM ubuntu:14.04
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

RUN apt-get update -y
RUN apt-get install -y curl git

RUN curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-deps | bash
RUN git clone https://github.com/torch/distro.git ~/torch --recursive
RUN cd ~/torch; ./install.sh

RUN source ~/.bashrc

RUN luarocks install nngraph
RUN luarocks install optim
RUN luarocks install nn

RUN luarocks install cltorch
RUN luarocks install clnn

docker build 运行良好,直到第一个 luarocks 调用:RUN luarocks install nngraph,此时它停止并抛出错误:

/bin/sh: luarocks: command not found

如果我注释掉 luarocks 行,构建运行良好。使用该图像,我可以创建一个容器并使用 bash,按预期运行 luarocks。

当然,我并不特别希望每次启动容器时都必须这样做,所以我想知道是否有什么可以做的。我感觉这个问题与RUN rm /bin/sh && ln -s /bin/bash /bin/sh 行有关,但我需要它才能运行RUN source ~/.bashrc 行。

谢谢。

【问题讨论】:

    标签: docker dockerfile luarocks


    【解决方案1】:

    每个 RUN 命令都在自己的 shell 上运行,并提交一个新层。

    来自 Docker 文档:

    RUN(命令在shell中运行 - /bin/sh -c -shell 表格)

    因此,当您运行 luarocks install <app> 时,它不会是您获取配置文件的同一个 shell。

    您必须提供 luarocks 运行的完整路径。请看下面我成功运行的修改后的 Dockerfile:

    FROM ubuntu:14.04
    RUN rm /bin/sh && ln -s /bin/bash /bin/sh
    
    RUN apt-get update -y
    RUN apt-get install -y curl git
    
    RUN curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-deps | bash
    RUN git clone https://github.com/torch/distro.git ~/torch --recursive
    RUN cd ~/torch; ./install.sh
    
    RUN source ~/.bashrc
    
    RUN /root/torch/install/bin/luarocks install nngraph
    RUN /root/torch/install/bin/luarocks install optim
    RUN /root/torch/install/bin/luarocks install nn
    RUN /root/torch/install/bin/luarocks install cltorch
    RUN /root/torch/install/bin/luarocks install clnn
    

    有关更多详细信息,请参阅 docker RUN 文档here

    【讨论】:

      【解决方案2】:

      正如 Alex da Silva 指出的那样,采购 .bashrc 发生在 Dockerfile 的另一个 shell 中。

      您也可以尝试让您的 luarocks 命令在与您的来源 bashrc 相同的 shell 中执行:

      ...
      RUN source ~/.bashrc && luarocks install nngraph
      RUN source ~/.bashrc && luarocks install optim
      RUN source ~/.bashrc && luarocks install nn
      
      RUN source ~/.bashrc && luarocks install cltorch
      RUN source ~/.bashrc && luarocks install clnn
      

      【讨论】:

        猜你喜欢
        • 2018-02-27
        • 2022-01-04
        • 1970-01-01
        • 2019-06-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-18
        • 2022-10-04
        • 2019-03-05
        相关资源
        最近更新 更多