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

查看:53
本文介绍了在 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.环境路径 $PATH:env/bin

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

3.<代码>运行.环境/bin/激活

我还遵循了 一个 Dockerfile 配置示例,用于Google Cloud 上的 python 运行时映像,与上面的内容基本相同.

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.

设置这些环境变量和运行 source/env/bin/activate 一样.

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

ENV VIRTUAL_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天全站免登陆