docker - 避免在每个 Docker 构建上重新安装包
问题描述
当我构建需要 TensorFlow(导入 tensorflow)的新 python 应用程序的图像时,每次 docker 安装 520 MB 的 TensorFlow。
如何避免这种情况?意味着只下载一次 tensorflow 并在构建许多图像时使用它?
Dockerfile
FROM python:3
WORKDIR /usr/src/app
COPY model.py .
COPY model_08015_07680.h5 .
COPY requirements.txt .
COPY images .
COPY labels.txt .
COPY test_run.py .
RUN pip install --no-cache-dir -r requirements.txt
CMD ["python","./test_run.py"]
要求.txt
numpy
opencv-python
tensorflow
解决方案
您不需要单独复制每个文件,这不是最佳选择。
另外,请记住 docker 是由层构建的,因此每条看起来可能会发生变化的行都位于底部。
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
#Copy everything
COPY . .
CMD ["python","./test_run.py"]
推荐阅读
- python - 使用 pygame 显示 unicode 符号
- javascript - 如何在 jsRender 中引用 json 对象属性?
- python - Pandas:访问列中字符串的不同方式
- excel - 如何仅从整个 Excel 工作簿中复制值而不打开它?
- javascript - 反应钩子不更新
- html - HTML 自定义框架
- javascript - 在 React Native 中显示/隐藏文本 onPress
- python - python数据结构查找跨越给定时间点的窗口
- php - 为什么我的 API 需要 2-3 秒来处理一个请求?
- go - 如何修复golang中的竞争条件?