From 80b0173d7c200ac65fed1b0aa689d83ebc322bf7 Mon Sep 17 00:00:00 2001 From: user123 Date: Sat, 10 Jan 2026 20:29:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9Containerd=E7=9A=84ns?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/docker.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/handlers/docker.go b/src/handlers/docker.go index 63a740b..eb89a35 100644 --- a/src/handlers/docker.go +++ b/src/handlers/docker.go @@ -28,9 +28,16 @@ var dockerProxy *DockerProxy type RegistryDetector struct{} // detectRegistryDomain 检测Registry域名并返回域名和剩余路径 -func (rd *RegistryDetector) detectRegistryDomain(path string) (string, string) { +func (rd *RegistryDetector) detectRegistryDomain(c *gin.Context, path string) (string, string) { cfg := config.GetConfig() + // 兼容Containerd的ns参数 + if ns := c.Query("ns"); ns != "" { + if mapping, exists := cfg.Registries[ns]; exists && mapping.Enabled { + return ns, path + } + } + for domain := range cfg.Registries { if strings.HasPrefix(path, domain+"/") { remainingPath := strings.TrimPrefix(path, domain+"/") @@ -99,7 +106,7 @@ func ProxyDockerRegistryGin(c *gin.Context) { func handleRegistryRequest(c *gin.Context, path string) { pathWithoutV2 := strings.TrimPrefix(path, "/v2/") - if registryDomain, remainingPath := registryDetector.detectRegistryDomain(pathWithoutV2); registryDomain != "" { + if registryDomain, remainingPath := registryDetector.detectRegistryDomain(c, pathWithoutV2); registryDomain != "" { if registryDetector.isRegistryEnabled(registryDomain) { c.Set("target_registry_domain", registryDomain) c.Set("target_path", remainingPath)