Akemi

Docker缓存污染报错

2025/06/11

流水线构建时,Jenkinsfile中自带的docker build命令报错:

以下镜像名均为假名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Commit message: "Merge branch '0606' into 'master'"
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git config core.sparsecheckout # timeout=10
> git checkout -f 15206a9bcaffb2ae0d1419a498d65319e535b2c7 # timeout=10
> git rev-list --no-walk 7a8c87003c159ffc5a4ce1d71f89b03e5c51a129 # timeout=10
[Pipeline] sh
+ cat /tmp/image_version.txt
+ image_version=202506091421
+ echo [jenkins log]: docker build start.
[jenkins log]: docker build start.
+ docker build -f Dockerfile -t xxx.cn-hangzhou.cr.aliyuncs.com/checker-backend:202506091421 .
Sending build context to Docker daemon 45.26MB

Step 1/13 : FROM xxx.cn-hangzhou.cr.aliyuncs.com/fastapi:python3.7.20230327
---> 7e715e055135
Step 2/13 : COPY ./utils /app/utils
---> 188d6d7a7ddf
Step 3/13 : COPY ./pchecker /app/pchecker
---> cf61c53f629d
Step 4/13 : COPY ./main.py ./requirements.txt /app/
failed to export image: failed to set parent sha256:cf61c53f629d364a65dd1b5b016ea7e0b999693d915ffcdfe1bbb3c7dc6794e1: unknown parent image ID sha256:cf61c53f629d364a65dd1b5b016ea7e0b999693d915ffcdfe1bbb3c7dc6794e1
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (git clone helm)
Stage "git clone helm" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (make changes and commit)
Stage "make changes and commit" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

关键报错信息:

failed to export image: failed to set parent sha256:cf61c53f629d364a65dd1b5b016ea7e0b999693d915ffcdfe1bbb3c7dc6794e1: unknown parent image ID sha256:cf61c53f629d364a65dd1b5b016ea7e0b999693d915ffcdfe1bbb3c7dc6794e1

排查过程:
1.尝试拉取FROM的镜像

sudo docker pull xxx.cn-hangzhou.cr.aliyuncs.com/fastapi:python3.7.20230327

发现镜像存在

2.查看COPY步骤中文件是否存在

3.缓存污染
留下了错误的父镜像层的无效引用

检查本地是否存在该层docker images --digests | grep cf61c53f629d

修改Jenkinsfile,不使用缓存进行构建:
+ docker build --no-cache -f Dockerfile -t xxx.cn-hangzhou.cr.aliyuncs.com/checker-backend:202506091421 .

随后再次重试,手动触发构建,就ok了

CATALOG