在Dockerfile使用RUN指令与“源”不起作用 [英] Using the RUN instruction in a Dockerfile with 'source' does not work

查看:797
本文介绍了在Dockerfile使用RUN指令与“源”不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我放在一起安装一个香草蟒蛇环境Dockerfile(进我将安装一个应用程序,但在稍后的日期)。

 从Ubuntu:12.04#需要建立一定的Python库
运行apt-get安装python-dev的-y从pip-installer.org规范的安装说明 - #画中画安装
#http://www.pip-installer.org/en/latest/installing.html
ADD https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py /tmp/ez_setup.py
ADD https://raw.github.com/pypa/pip/master/contrib/get-pip.py /tmp/get-pip.py
运行Python /tmp/ez_setup.py
运行Python /tmp/get-pip.py
RUN安装PIP画中画--upgrade#安装和配置的virtualenv
RUN PIP安装的virtualenv
RUN PIP安装virtualenvwrapper
ENV WORKON_HOME〜/ .virtualenvs
RUN的mkdir -p $ WORKON_HOME
RUN源/usr/local/bin/virtualenvwrapper.sh

构建运行正常,直到最后一行,在那里我得到了以下异常:

  [1-9为了清楚起见去previous步骤]
...
成功安装virtualenvwrapper的virtualenv克隆装卸工
打扫干净...
 ---> 1fc253a8f860
步骤10:ENV WORKON_HOME〜/ .virtualenvs
 --->跑在8b0145d2c80d
 ---> 0f91a5d96013
第11步:运行的mkdir -p $ WORKON_HOME
 --->跑在9d2552712ddf
 ---> 3a87364c7b45
第12步:运行源/usr/local/bin/virtualenvwrapper.sh
 --->跑在c13a187261ec
/ bin / sh的:1:来源:未找到

如果我 LS 进入该目录(只是为了测试该previous步骤是承诺),我可以看到存在的文件预期:

  $泊坞窗运行3a87 LS的/ usr / local / bin目录
easy_install的
easy_install的-2.7
果仁
PIP-2.7
的virtualenv
的virtualenv-2.7
virtualenv中克隆
virtualenvwrapper.sh
virtualenvwrapper_lazy.sh

如果我尝试只运行命令我得到同样的'未找到'错误如上。但是,如果我运行一个交互式shell会话,源不工作:

  $泊坞窗运行3a87庆典
资源
击:第1行:需文件名参数:源
来源:用法:源文件名[参数]

我可以从这里运行的脚本,然后愉快地访问 workon mkvirtualenv 等。

我已经做了一些挖掘,初步看起来好像这个问题可能在于作为Ubuntu的的登录shell 的,和破折号庆典的区别作为Ubuntu的的系统shell 破折号不支持命令。

不过,这个问题的答案似乎是使用而不是,但这恰恰使泊坞窗运行时吹了一展身手的恐慌异常。

什么是运行从Dockerfile运行指令的shell脚本来解决这个问题的最好办法(正在运行关闭Ubuntu的LTS 12.04的默认基础映像)。


解决方案

 从Ubuntu:14.04
RUN RM / bin / sh的&放大器;&安培; LN -s /斌/ bash的/ bin / sh的

这应该适用于每一个Ubuntu的码头工人的基本图像。我一般加入这一行,每Dockerfile我写的。

I have a Dockerfile that I am putting together to install a vanilla python environment (into which I will be installing an app, but at a later date).

FROM ubuntu:12.04

# required to build certain python libraries
RUN apt-get install python-dev -y

# install pip - canonical installation instructions from pip-installer.org
# http://www.pip-installer.org/en/latest/installing.html
ADD https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py /tmp/ez_setup.py
ADD https://raw.github.com/pypa/pip/master/contrib/get-pip.py /tmp/get-pip.py
RUN python /tmp/ez_setup.py
RUN python /tmp/get-pip.py
RUN pip install --upgrade pip 

# install and configure virtualenv
RUN pip install virtualenv 
RUN pip install virtualenvwrapper
ENV WORKON_HOME ~/.virtualenvs
RUN mkdir -p $WORKON_HOME
RUN source /usr/local/bin/virtualenvwrapper.sh

The build runs ok until the last line, where I get the following exception:

[previous steps 1-9 removed for clarity]
...
Successfully installed virtualenvwrapper virtualenv-clone stevedore
Cleaning up...
 ---> 1fc253a8f860
Step 10 : ENV WORKON_HOME ~/.virtualenvs
 ---> Running in 8b0145d2c80d
 ---> 0f91a5d96013
Step 11 : RUN mkdir -p $WORKON_HOME
 ---> Running in 9d2552712ddf
 ---> 3a87364c7b45
Step 12 : RUN source /usr/local/bin/virtualenvwrapper.sh
 ---> Running in c13a187261ec
/bin/sh: 1: source: not found

If I ls into that directory (just to test that the previous steps were committed) I can see that the files exist as expected:

$ docker run 3a87 ls /usr/local/bin
easy_install
easy_install-2.7
pip
pip-2.7
virtualenv
virtualenv-2.7
virtualenv-clone
virtualenvwrapper.sh
virtualenvwrapper_lazy.sh

If I try just running the source command I get the same 'not found' error as above. If I RUN an interactive shell session however, source does work:

$ docker run 3a87 bash
source
bash: line 1: source: filename argument required
source: usage: source filename [arguments]

I can run the script from here, and then happily access workon, mkvirtualenv etc.

I've done some digging, and initially it looked as if the problem might lie in the difference between bash as the Ubuntu login shell, and dash as the Ubuntu system shell, dash not supporting the source command.

However, the answer to this appears to be to use '.' instead of source, but this just causes the Docker runtime to blow up with a go panic exception.

What is the best way to run a shell script from a Dockerfile RUN instruction to get around this (am running off the default base image for Ubuntu 12.04 LTS).

解决方案

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

This should work for every Ubuntu docker base image. I generally add this line for every Dockerfile I write.

这篇关于在Dockerfile使用RUN指令与“源”不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆