在带有“源"的 Dockerfile 中使用 RUN 指令不起作用

编程入门 行业动态 更新时间:2024-10-27 08:28:41
本文介绍了在带有“源"的 Dockerfile 中使用 RUN 指令不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 Dockerfile,我正在将它放在一起来安装一个普通的 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 # www.pip-installer/en/latest/installing.html ADD bitbucket/pypa/setuptools/raw/bootstrap/ez_setup.py /tmp/ez_setup.py ADD raw.github/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

如果我尝试只运行 source 命令,我会遇到与上面相同的未找到"错误.但是,如果我运行交互式 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 和 dash 之间的区别 作为 Ubuntu system shell,dash 不支持 source 命令.

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 RUN 指令运行 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).

推荐答案

我的答案是陈旧的.我认为另一个答案更好.

My answer is stale. I think that another answers is better.

RUN/bin/bash -c "source/usr/local/bin/virtualenvwrapper.sh"

更多推荐

在带有“源"的 Dockerfile 中使用 RUN 指令不起作用

本文发布于:2023-11-24 11:10:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624964.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指令   不起作用   quot   Dockerfile   RUN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!