在Docker文件中使用“source”的RUN指令不起作用 [英] Using the RUN instruction in a Dockerfile with 'source' does not work

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

问题描述

我有一个Docker文件,我正在放在一起安装一个香草python环境(我将在其中安装一个应用程序,但稍后)。

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

如果我 ls 到该目录(只是为了测试以前的步骤是否提交)我可以看到文件按预期存在:

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

如果我尝试运行源代码命令,我会得到与上述相同的未找到错误。如果我运行一个交互式shell会话,但是源代码可以正常工作:

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]

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

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

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

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.

但是,这个答案似乎是使用'。',而不是 source ,但是这只会导致Docker运行时出现一个go panic异常。

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.

从Dockerfile运行shell脚本的最佳方法是什么解决这个问题的指示(正在运行Ubuntu 12.04 LTS的默认基本映像)。

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).

推荐答案

RUN / bin / bash -csource /usr/local/bin/virtualenvwrapper.sh

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

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