It seems that how you specify your layers in the Dockerfile is important.
Using the ncdu tool (thanks for that btw jeremy!) I notice the following:
/root/.cache/pip = 249.3MB (247.9 of this is under the /http folder). Question: Can I remove this from the image? If so, that give me back 250MB which would be nice.
/usr/local/lib/python3.7/site-packages = 842.7Mb. torch is the biggest package at 341.7Mb and outside of that, everything looks reasonable with scipy, numpy, spacy, pandas adding collectively another 231Mbs.
So aside from being able to remove the /root/.cache files, it doesn’t look like there is much else I can do to reduce the file size. So another question: What is a reasonable image size of an inference only docker image? I know the answer is probably app-specific, but would be great to hear what other folks are seeing and to know if I’m in the ballpark of it looking right or off.
Here is my latest Dockerfile if anyone is interested:
RUN apt-get update && apt-get install -y ncdu \
&& rm -rf /var/lib/apt/lists/*
COPY ./app/api/requirements.txt /app
RUN pip install --upgrade pip
RUN pip install --upgrade -r requirements.txt
RUN rm -rf /root/.cache
COPY ./app/api /app
re: Question: *Can I remove /root/.cache/pip from the image? Seems like the answer is “yes” (see Dockerfile below) … and doing so brings the image to ~ 2.05GB.
Here is a screenshot of what ncdu tells me after making these changes:
There is a difference between an image and a container … so it seems the size of the image is 3.24GB while the size of an instance of that image running is 2.2GB.
This article may help … I’m by no means an expert on Docker and so I may be off myself. As you can see, when I deploy to AWS ECS it comes back as much smaller (and I’m assuming AWS does some kind of compression to make that happen).