Skip to content

Modern Docker Management, Designed for Everyone

fix: streamline image reference handling by stripping digests and ensuring tags

Kyle Mendellc2a3b7d566b0
diff --git a/backend/internal/services/image_service.go b/backend/internal/services/image_service.go
index cfb7b5df4..e381e5b76 100644
--- a/backend/internal/services/image_service.go
+++ b/backend/internal/services/image_service.go
@@ -225,28 +225,23 @@ func (s *ImageService) getPullOptionsWithAuth(ctx context.Context, imageRef stri
}
func (s *ImageService) extractRegistryHost(imageRef string) string {
- parts := strings.Split(imageRef, "@")
- if len(parts) > 1 {
- imageRef = parts[0]
+ // strip digest if present
+ if i := strings.Index(imageRef, "@"); i != -1 {
+ imageRef = imageRef[:i]
}
-
- parts = strings.Split(imageRef, ":")
- if len(parts) > 1 {
- imageRef = parts[0]
- }
-
- parts = strings.Split(imageRef, "/")
-
- if len(parts) == 1 {
+ // if no slash, it's a Docker Hub shorthand
+ if !strings.Contains(imageRef, "/") {
return "docker.io"
}
+ // first segment before first "/" is either a registry host[:port] or a namespace
+ firstSlash := strings.Index(imageRef, "/")
+ hostCandidate := imageRef[:firstSlash]
- firstPart := parts[0]
- if strings.Contains(firstPart, ".") || strings.Contains(firstPart, ":") {
- return firstPart
+ // if it doesn't look like a host (no dot/colon), default to docker.io
+ if !strings.Contains(hostCandidate, ".") && !strings.Contains(hostCandidate, ":") {
+ return "docker.io"
}
-
- return "docker.io"
+ return hostCandidate
}
func (s *ImageService) isRegistryMatch(credURL, registryHost string) bool {
@@ -261,10 +256,14 @@ func (s *ImageService) normalizeRegistryForComparison(url string) string {
url = strings.TrimPrefix(url, "http://")
url = strings.TrimSuffix(url, "/")
+ // keep only host part (drop any path like ghcr.io/org or /v2/)
+ if slash := strings.Index(url, "/"); slash != -1 {
+ url = url[:slash]
+ }
+
if url == "docker.io" || url == "registry-1.docker.io" || url == "index.docker.io" {
return "docker.io"
}
-
return url
}
diff --git a/backend/internal/services/stack_service.go b/backend/internal/services/stack_service.go
index dee7af854..1c51767fe 100644
--- a/backend/internal/services/stack_service.go
+++ b/backend/internal/services/stack_service.go
@@ -440,7 +440,9 @@ func (s *StackService) pullImagesViaImageService(ctx context.Context, stack *mod
})
var firstErr error
- for _, img := range images {
+ for _, raw := range images {
+ img := refForPull(raw) // strip digest and ensure a tag
+
le.WriteJSON(map[string]any{"status": "Pulling", "id": img})
if err := s.imageService.PullImage(ctx, img, w, systemUser); err != nil {
@@ -467,6 +469,22 @@ func (s *StackService) pullImagesViaImageService(ctx context.Context, stack *mod
return firstErr
}
+// refForPull strips any digest from the reference and ensures a tag (defaults to ":latest")
+func refForPull(ref string) string {
+ ref = strings.TrimSpace(ref)
+ // remove digest if present
+ if i := strings.Index(ref, "@"); i != -1 {
+ ref = ref[:i]
+ }
+ // ensure a tag exists; consider ":" only if it appears after the last "/"
+ lastSlash := strings.LastIndex(ref, "/")
+ lastColon := strings.LastIndex(ref, ":")
+ if lastColon <= lastSlash {
+ ref += ":latest"
+ }
+ return ref
+}
+
func (s *StackService) composePull(ctx context.Context, stack *models.Stack, w io.Writer) error {
le := newLineEmitter(w)