gpt4 book ai didi

docker - 避免在每个Docker构建中重新安装软件包

转载 作者:行者123 更新时间:2023-12-02 19:48:30 24 4
gpt4 key购买 nike

当我构建需要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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com