将自定义模块安装到Docker容器中 [英] Installing custom modules into docker container
问题描述
我有几个服务在各自的Docker容器中运行。在我的项目中,我还有一个 lib
文件夹,其中包含一些所有服务都需要的小模块。
I have several services running in their own Docker containers. In my project I also have a lib
folder containing some small modules that all the services need.
将这些模块包含在Docker容器中的最佳方法是什么?显然,第三方模块我只使用 RUN pip install -r requirements.txt
,有没有类似的方法可以包含我自己的模块?
What is the best way to include these modules into the Docker containers? Obviously third party modules I just use RUN pip install -r requirements.txt
, is there a similar way I can include my own modules?
推荐答案
我最终通过使用将
,像这样: lib
文件夹安装到容器中来对其进行管理docker-compose
I ended up managing it out by mounting the lib
folder into the container using docker-compose
, like so:
version: '2'
services:
frontend_web:
build: .
volumes:
- ../../lib:/app/lib
然后我只需要将/ app / lib添加到容器的 PYTHONPATH
中,就可以从该文件夹导入任何模块。
I then just had to add /app/lib to the container's PYTHONPATH
and I could import any module from that folder.
这篇关于将自定义模块安装到Docker容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!