| shell 形式 | RUN apt-get update && apt-get install -y curl(经 /bin/sh -c) |
|---|---|
| exec 形式 | RUN ["apt-get","install","-y","curl"](不经 shell,无变量展开) |
| 分层规则 | 一条 RUN 一层:合并安装、清理、建目录操作 |
| 缓存 | 命令文本不变即复用缓存;必要时 docker build --no-cache |
| 可调试 | set -eux 开头:出错即停且回显每条命令 |
同层安装并清理
同层安装并清理
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends curl ca-certificates; \
rm -rf /var/lib/apt/lists/*不要把清理放到下一条 RUN:文件已在上一层固化,镜像体积不会减小。