在Dockerfile中激活python virtualenv [英] Activate python virtualenv in Dockerfile

查看:255
本文介绍了在Dockerfile中激活python virtualenv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Dockerfile,之后我尝试在其中激活python virtualenv,它应该在此env中安装所有依赖项。但是,所有内容仍会在全球范围内安装。我使用了不同的方法,但没有一个起作用。我也没有得到任何错误。哪里有问题?

I have a Dockerfile where I try to activate python virtualenv after what, it should install all dependencies within this env. However, everything still gets installed globally. I used different approaches and non of them worked. I also do not get any errors. Where is a problem?

1。
ENV PATH $ PATH:env / bin

2。
环境路径$ PATH:env / bin / activate

3。
RUN。 env / bin / activate

我还遵循了在Google Cloud上为python运行时映像配置Dockerfile的示例,与上面的基本相同。

I also followed an example of a Dockerfile config for the python-runtime image on Google Cloud, which is basically the same stuff as above.


设置这些环境变量与运行源代码/ env / bin / activate相同。

Setting these environment variables are the same as running source /env/bin/activate.

ENV VIRTUAL_ENV / env

ENV路径/ env / bin:$ PATH

此外, ENV VIRTUAL_ENV / env 是什么意思,以及如何

Additionally, what does ENV VIRTUAL_ENV /env mean and how it is used?

推荐答案

您不需要在Docker容器内使用virtualenv。

virtualenv 用于隔离依赖项。您要防止安装的任何依赖项或软件包在应用程序之间泄漏。 Docker 实现了相同的目的,它隔离了容器内的依赖关系并防止了容器之间以及应用程序之间的泄漏。

virtualenv is used for dependency isolation. You want to prevent any dependencies or packages installed from leaking between applications. Docker achieves the same thing, it isolates your dependencies within your container and prevent leaks between containers and between applications.

因此,没有意义在Docker容器内使用virtualenv的情况下,除非您在同一个容器中运行多个应用程序,否则我会说您做错了,解决方案是以更好的方式构建应用程序并将其拆分在多个容器中。

Therefor, there is no point in using virtualenv inside a Docker Container unless you are running multiple apps in the same container, if that's the case I'd say that you're doing something wrong and the solution would be to architect your app in a better way and split them up in multiple containers.

这篇关于在Dockerfile中激活python virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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