【发布时间】:2022-01-19 12:15:59
【问题描述】:
我用一些 apt 和 pip 包为 jupyterlab 构建 dockerimages。
docker image ls:
jupyterlab 3.7.12 9d4cc5c15853 27 minutes ago 2.3GB
jupyterlab 3.9.9 1962a1eb6bff 25 hours ago 1.12GB
图片的文件大小差别很大,我只拿了另一个python版本。
以下是用于比较的 dockerfile: 这个 dockerfile 是用 python 3.7.12 作为基础镜像构建的:
FROM python:3.7.12-slim-buster
WORKDIR /
COPY wheels/scipy-1.7.3-cp37-cp37m-linux_armv7l.whl ./wheels/scipy-1.7.3-cp37-cp37m-linux_armv7l.whl
## INSTALL WITH APK
RUN apt-get update && apt-get install -y \
g++ \
gcc \
python3-dev \
libjpeg-dev \
zlib1g-dev \
make \
wget \
libatlas-base-dev \
libffi-dev
## INSTALL WITH PIP
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir pillow && \
pip install --no-cache-dir matplotlib && \
pip install --no-cache-dir pandas && \
pip install --no-cache-dir setuptools && \
pip install --no-cache-dir cffi && \
pip install --no-cache-dir GLIBC && \
pip install --no-cache-dir numpy && \
pip install --no-cache-dir /wheels/scipy-1.7.3-cp37-cp37m-linux_armv7l.whl && \
pip install --no-cache-dir jupyterlab
# pip install --no-cache-dir /wheels/numpy-1.21.4-cp39-cp39-linux_armv7l.whl && \
# pip install --no-cache-dir /wheels/scipy-1.7.2-cp39-cp39-linux_armv7l.whl && \
# pip install --no-cache-dir /wheels/jupyterlab-4.0.0a15-py3-none-any.whl
...
这是以python 3.9.9为基础镜像的那个:
FROM python:3.9.9-slim-buster
WORKDIR /
COPY wheels ./wheels
## INSTALL WITH APK
RUN apt-get update && apt-get install -y \
g++ \
gcc \
python3-dev \
libjpeg-dev \
zlib1g-dev \
make \
wget \
libatlas-base-dev \
libffi-dev
## INSTALL WITH PIP
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir pillow && \
pip install --no-cache-dir matplotlib && \
pip install --no-cache-dir pandas && \
pip install --no-cache-dir setuptools && \
pip install --no-cache-dir cffi && \
pip install --no-cache-dir GLIBC && \
pip install --no-cache-dir /wheels/numpy-1.21.4-cp39-cp39-linux_armv7l.whl && \
pip install --no-cache-dir /wheels/scipy-1.7.2-cp39-cp39-linux_armv7l.whl && \
pip install --no-cache-dir /wheels/jupyterlab-4.0.0a15-py3-none-any.whl
...
wheels 文件夹和其他一些文件在这两种情况下都会被删除。 为什么文件大小差别这么大???
【问题讨论】:
-
3.7.12 安装了一个未命名的 jupyterLab 版本,但 3.9.9 安装了一个命名版本(4.0.0),所以我怀疑这有什么区别?除此之外......安装的版本在两者中都不同如果您想知道大小差异的真正原因,那么您应该能够自己解决。从每个基础镜像开始,然后单独添加层(或包),看看每个层有什么不同。
-
问题是,它在我的机器上构建了 2 个小时,所以尝试使用不同的 dockerfile 需要很长时间。如果不是通过下载的 whl 安装,我认为 Jupyterlab 不会多占用 1GB 的空间。
-
对于每个 Dockerfile,您可以将每个
pip install命令作为单独的 RUN 语句运行,以便它们各自获得一个层,然后比较层大小,这应该可以让您很好地了解差异来自哪里.在构建的图像上使用docker history命令查看图层大小。 -
我不想使用太多层,但对于测试这应该足够了。谢谢你的建议。