首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Dockerfile中使用带有'source‘的RUN指令不起作用

在Dockerfile中使用带有'source‘的RUN指令不起作用
EN

Stack Overflow用户
提问于 2013-12-17 21:29:35
回答 18查看 301.4K关注 0票数 354

我有一个Dockerfile,我正在把它放在一起来安装一个普通的python环境(我将在这个环境中安装一个应用程序,但以后再安装)。

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

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

[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

如果我使用ls进入该目录(只是为了测试前面的步骤是否被提交),我可以看到文件如预期的那样存在:

$ 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

如果我只尝试运行source命令,我会得到与上面一样的“找不到”错误。但是,如果我运行一个交互式shell会话,source确实可以工作:

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

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

我做了一些挖掘,最初看起来问题可能出在bash作为Ubuntu登录外壳,dash作为Ubuntu系统外壳,dash不支持source命令之间的差异。

然而,这个问题的答案似乎是使用‘.而不是source,但这只会导致Docker运行时崩溃并引发go异常。

从Dockerfile运行指令中运行shell脚本的最佳方式是什么来解决这个问题(我运行的是Ubuntu 12.04 LTS的默认基础映像)。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20635472

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档