一次RUN指令形成新的一层,尽量Shell命令都写在一行,减少镜像层。
一次RUN形成新的一层,如果没有在同一层删除,无论文件是否最后删除,都会带到下一层,所以要在每一层清理对应的残留数据,减小镜像大小。
比如centos中,用yum安装之后,及时清理缓存
yum clean all && rm -rf /var/cache/yum/*
比如ubuntu中用apt-get安装,可以加上--no-install-recommends这个参数,不安装非必须的依赖包
比如:RUN apt-get update && apt-get install -y --no-install-recommends curl telnet wget python-pip -y && rm -rf /var/cache/apk/* && rm -rf /var/lib/apt/lists/* && apt-get autoremove
pip安装,加上pip --no-cache-dir
RUN pip --no-cache-dir install httpstat
参考网址:https://blog.51cto.com/lizhenliang/2363565
原文:https://www.cnblogs.com/tianfen/p/11045032.html