1

我有一个用于一些 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

谢谢。

4

2 回答 2

4

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

从 Docker 文档中:

RUN(命令以 shell - /bin/sh -c - shell 形式运行)

因此,当您运行时,luarocks install <app>它与您获取配置文件的外壳不同。

您必须提供 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 文档。

于 2015-10-03T03:41:12.177 回答
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
于 2015-10-03T05:19:08.620 回答