一些运行不会在docker工作,但会在容器内

我有一个Dockerfile的一些lua和火炬相关的任务,我试图用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 

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

当然,我不是特别想在每次启动容器时都这样做,所以我想知道是否有任何事情可以做到这一点。 我有一种感觉,这个问题与RUN rm /bin/sh && ln -s /bin/bash /bin/sh但是我需要能够运行RUN source ~/.bashrc这一行。

谢谢。

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

从Docker文档:

RUN(命令运行在shell – / bin / sh -c – shellforms中)

所以当你运行luarocks install <app>它不会是你的资料来源。

你必须提供luarocks运行的完整path。 看到下面我修改的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文档。

正如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