简体   繁体   English

Docker和pip要求

[英]Docker and pip requirements

I want to maintain the development environment for a python application that needs dependencies installed with pip . 我想维护需要使用pip安装的依赖项的python应用程序的开发环境。

I plan to have the source code (including requirements.txt ) pulled from a git repo into a host folder which is mounted as a docker volume. 我打算将源代码(包括requirements.txt )从git存储库中拉到作为docker卷安装的主机文件夹中。

Is there a docker pattern to keep the libraries updated and yet avoid the expensive pip install -r requirements.txt with every git pull ? 是否有一个docker模式可以保持库的更新,并且避免每次git pull都使用昂贵的pip install -r requirements.txt

The way to avoid installing every time is to do the pip install in a separate RUN instruction before you pull the whole repo. 避免每次安装的方法是在拉动整个存储库之前,在单独的RUN指令中进行pip install To do that you'll need another way to get your requirements.txt into the container - maybe with ADD , specifying the full remote URL: 为此,您将需要另一种方式来将您的requirements.txt放入容器中-也许使用ADD ,指定完整的远程URL:

ADD https://raw.githubusercontent.com/etc/requirements.txt .
RUN pip install -r requirements.txt

When you docker build this, if the contents of requirements.txt hasn't changed then the cached layer with all the installed dependencies will be used. 当您在docker build ,如果requirements.txt的内容未更改,则将使用具有所有已安装依赖项的缓存层。 If the requirements file has changed, then the install will run again. 如果需求文件已更改,则安装将再次运行。

If you go with this, you'll want specific versions in your requirements file, and you'll have to manually update it for version bumps. 如果这样做,您将需要在需求文件中使用特定版本,并且必须手动更新它以防止版本增加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM