当我构建需要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"]
requirements.txt
numpy
opencv-python
tensorflow
最佳答案
请使用下面经过优化的Dockerfile
,因为它不会一次又一次安装依赖项,直到/除非您更改requirements.txt
FROM python:3
WORKDIR /usr/src/app
#Copy Requirements
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
#Copy everything later, as below parts will be changing and above part will be used from cache
COPY model.py .
COPY model_08015_07680.h5 .
COPY images .
COPY labels.txt .
COPY test_run.py .
CMD ["python","./test_run.py"]
关于docker - 避免在每个Docker构建中重新安装软件包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62231980/