From ac1f49f8dd2785485d6388a7b6f2649bd2d35cd1 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 25 Nov 2025 22:25:18 +0800 Subject: [PATCH] fix: Fix the issue of abnormal image list retrieval in snapshots (#11074) Refs #11030 --- agent/app/service/snapshot_create.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/agent/app/service/snapshot_create.go b/agent/app/service/snapshot_create.go index 937c26a95..cc2c014c0 100644 --- a/agent/app/service/snapshot_create.go +++ b/agent/app/service/snapshot_create.go @@ -12,6 +12,7 @@ import ( "time" "github.com/1Panel-dev/1Panel/agent/app/repo" + "github.com/docker/docker/api/types/image" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/model" @@ -23,6 +24,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/utils/common" "github.com/1Panel-dev/1Panel/agent/utils/controller" "github.com/1Panel-dev/1Panel/agent/utils/copier" + "github.com/1Panel-dev/1Panel/agent/utils/docker" "github.com/1Panel-dev/1Panel/agent/utils/files" "gorm.io/gorm" ) @@ -369,9 +371,21 @@ func snapAppImage(snap snapHelper, req dto.SnapshotCreate, targetDir string) err } } + client, err := docker.NewDockerClient() + if err != nil { + snap.Task.Log("load docker client failed, skip save app images") + return nil + } + images, err := client.ImageList(context.Background(), image.ListOptions{}) + if err != nil { + snap.Task.Log("list docker images failed, skip save app images") + return nil + } + var existImages []string + for _, img := range images { + existImages = append(existImages, img.RepoTags...) + } var imageList []string - existStr, _ := cmd.RunDefaultWithStdoutBashC("docker images | awk '{print $1\":\"$2}' | grep -v REPOSITORY:TAG") - existImages := strings.Split(existStr, "\n") for _, app := range req.AppData { for _, item := range app.Children { if item.Label == "appImage" && item.IsCheck {