症状
ERROR: failed to solve: process "/bin/sh -c ..." did not complete successfully: exit code N。若上游更新了基础镜像标签,它可能突然开始出现。
诊断
提取失败的命令并以交互方式运行:
docker run --rm -it ubuntu:22.04 sh
# then paste the failing command to see its output
apt-get update
用 --no-cache 重建以排除陈旧层的影响。
修复
固定基础镜像并修复该步骤:
FROM ubuntu:22.04@sha256:<digest>
RUN apt-get update && apt-get install -y --no-install-recommends curl
确保 COPY 源存在且未被 .dockerignore 排除。
验证
重建镜像;所有步骤完成,原先失败的命令以 0 退出,产出预期的镜像。