[英]Decrease Docker Image Size
So I am trying to deploy a multi container service(web, worker, redis) using docker-compose to ECS.所以我正在尝试使用 docker-compose 将多容器服务(web、worker、redis)部署到 ECS。 The service has a ML model which requires Tensorflow and Keras as dependencies.该服务有一个 ML 模型,需要 Tensorflow 和 Keras 作为依赖项。 After running the pip install -r requirements.txt, the image size increases to more than 2gb, 1.75gb of which are dependencies.运行pip install -r requirements.txt后,镜像大小增加到2g多,其中1.75gb是依赖。 Is there a way to decrease this image size?有没有办法减少这个图像大小? Since deploying such a large image on cloud has a lot of cons?既然在云上部署这么大的镜像有很多弊端?
Dockerfile for web:用于网络的 Dockerfile:
FROM python:3.6
WORKDIR .
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 5000
CMD ["python", "views.py"]
requirements.txt:
Flask==1.1.2
numpy==1.18.5
opencv-python==4.2.0.34
Pillow==7.1.2
redis==3.5.3
rq==1.4.3
boto3
pymongo
Keras==2.2.4
tensorflow==1.15.0
matplotlib
Given that your dependencies are causing the increase of 1.75GB you should start there.鉴于您的依赖项导致 1.75GB 的增加,您应该从那里开始。 There is no easy silver bullet.没有简单的银弹。 These are the first steps:这些是第一步:
pip install --no-cache-dir -r requirements.txt && rm -rf somepath
the docker image will not grow.如果您在pip install --no-cache-dir -r requirements.txt && rm -rf somepath
之后立即删除,则 docker 映像将不会增长。python:3.6-slim
instead.你可以试试python:3.6-slim
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.