【问题标题】:How to install some python packages in Docker Container如何在 Docker Container 中安装一些 python 包
【发布时间】:2019-03-12 13:35:20
【问题描述】:

我正在使用“reportlab”。 每次进入docker环境时我都必须安装“pip install reportlab”,我不想每次都安装任何解决方案。

【问题讨论】:

  • RUN pip install reportlab添加到Dockerfile,或者如果你已经在Dockerfile中安装了requirements.txt,那么添加reportlab到它。
  • Docker 有一个official tutorial on building and running custom images,这是一个很好的起点;它甚至是专注于 Python 的,这应该能够帮助你。直接在正在运行的容器中安装软件包不是最佳做法,因为您很可能会丢掉工作。

标签: python django docker


【解决方案1】:

您可以设置一个requirements.txt 文件,然后在您的Dockerfile 中包含类似的内容:

ADD requirements.txt /code/  # I've assumed code is where you keep your dev files
WORKDIR /code  # where to run docker commands
RUN pip install -r requirements.txt  # install the dependencies

您不仅可以将reportlab,还可以将所有其他项目依赖项放入该文件中(这是 Python 项目中的常见模式)。

此外,根据您运行应用的方式,您要确保在退出容器时不要删除它。

【讨论】:

    【解决方案2】:

    登录到容器,安装所有必要的组件并构建映像。该图像可以重复用于旋转新容器。

    Docker 提交

    https://docs.docker.com/engine/reference/commandline/commit/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-28
      • 2016-09-18
      • 1970-01-01
      • 2018-12-06
      相关资源
      最近更新 更多