Using the RUN instruction in a Dockerfile with 'source' does not work

問題:

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).我有一個 Dockerfile,我將它放在一起來安裝一個 vanilla 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

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:如果我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

If I try just running the source command I get the same 'not found' error as above.如果我嘗試只運行source命令,我會收到與上面相同的“未找到”錯誤。 If I RUN an interactive shell session however, source does work:但是,如果我運行交互式 shell 會話,源代碼確實有效:

$ 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.我可以從這裏運行腳本,然後愉快地訪問workonmkvirtualenv等。

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.我已經做了一些挖掘,最初看起來問題可能在於bash作爲 Ubuntu登錄 shelldash作爲 Ubuntu系統 shell之間的區別, dash不支持source命令。

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.而不是source ,但這隻會導致 Docker 運行時因 go panic 異常而崩潰。

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).從 Dockerfile RUN 指令運行 shell 腳本來解決這個問題的最佳方法是什麼(我正在運行 Ubuntu 12.04 LTS 的默認基本映像)。


解決方案:

參考一: https://en.stackoom.com/question/1OaEC
參考二: https://stackoom.com/question/1OaEC
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章