@@ -11,6 +11,7 @@ import (
1111 "github.com/docker/model-runner/cmd/cli/desktop"
1212 "github.com/docker/model-runner/cmd/cli/pkg/standalone"
1313 "github.com/docker/model-runner/pkg/inference/backends/vllm"
14+ "github.com/google/go-containerregistry/pkg/name"
1415 "github.com/moby/term"
1516 "github.com/spf13/cobra"
1617)
@@ -26,6 +27,16 @@ const (
2627 enableVLLM = "It looks like you're trying to use a model for vLLM → docker model install-runner --vllm"
2728)
2829
30+ // getDefaultRegistry returns the default registry, checking for environment override
31+ // If DEFAULT_REGISTRY environment variable is set, it returns that value
32+ // Otherwise, it returns name.DefaultRegistry ("index.docker.io")
33+ func getDefaultRegistry () string {
34+ if defaultReg := os .Getenv ("DEFAULT_REGISTRY" ); defaultReg != "" {
35+ return defaultReg
36+ }
37+ return name .DefaultRegistry
38+ }
39+
2940var notRunningErr = fmt .Errorf ("Docker Model Runner is not running. Please start it and try again.\n " )
3041
3142func handleClientError (err error , message string ) error {
@@ -87,15 +98,47 @@ func asPrinter(cmd *cobra.Command) standalone.StatusPrinter {
8798 return & commandPrinter {cmd : cmd }
8899}
89100
90- // stripDefaultsFromModelName removes the default "ai/" prefix and ":latest" tag for display.
101+ // stripDefaultsFromModelName removes the default "ai/" prefix, default registry, and ":latest" tag for display.
91102// Examples:
92103// - "ai/gemma3:latest" -> "gemma3"
93- // - "ai/gemma3:v1" -> "ai/ gemma3:v1"
104+ // - "ai/gemma3:v1" -> "gemma3:v1"
94105// - "myorg/gemma3:latest" -> "myorg/gemma3"
95106// - "gemma3:latest" -> "gemma3"
107+ // - "index.docker.io/ai/gemma3:latest" -> "gemma3"
108+ // - "docker.io/ai/gemma3:latest" -> "gemma3"
109+ // - "docker.io/myorg/gemma3:latest" -> "myorg/gemma3"
96110// - "hf.co/bartowski/model:latest" -> "hf.co/bartowski/model"
97111func stripDefaultsFromModelName (model string ) string {
98- // Check if model has ai/ prefix without tag (implicitly :latest) - strip just ai/
112+ // Get the current default registry (checking for environment override)
113+ defaultRegistry := getDefaultRegistry ()
114+
115+ // Handle the common default registries that are aliases for each other
116+ // Always handle "index.docker.io" and "docker.io" as defaults regardless of DEFAULT_REGISTRY env var
117+ // since they are equivalent and commonly used interchangeably
118+ defaultRegistries := []string {"index.docker.io/" , "docker.io/" }
119+ if defaultRegistry != "" &&
120+ defaultRegistry != "index.docker.io" &&
121+ defaultRegistry != "docker.io" {
122+
123+ // Ensure it has a trailing slash for correct prefix trimming
124+ if ! strings .HasSuffix (defaultRegistry , "/" ) {
125+ defaultRegistry += "/"
126+ }
127+ // Overwrite the list to contain only the custom registry
128+ defaultRegistries = []string {defaultRegistry }
129+ }
130+
131+ // Check for the common default registries first
132+ for _ , reg := range defaultRegistries {
133+ if strings .HasPrefix (model , reg ) {
134+ // Remove the registry prefix
135+ model = strings .TrimPrefix (model , reg )
136+ break
137+ }
138+ }
139+
140+ // If model has default org prefix (without tag, or with :latest tag), strip the org
141+ // but preserve other tags
99142 if strings .HasPrefix (model , defaultOrg + "/" ) {
100143 model = strings .TrimPrefix (model , defaultOrg + "/" )
101144 }
0 commit comments