Skip to content

Commit 0efa602

Browse files
authored
Merge pull request #61 from docker/cloud-default-port
standalone: use different default port for Cloud installs
2 parents 5be97cf + 457b024 commit 0efa602

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

commands/compose.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ func newUpCommand() *cobra.Command {
5151
_ = setenv("URL", "http://model-runner.docker.internal/engines/v1/")
5252
} else if kind == desktop.ModelRunnerEngineKindMobyManual {
5353
_ = setenv("URL", modelRunner.URL("/engines/v1/"))
54-
} else if kind == desktop.ModelRunnerEngineKindMoby || kind == desktop.ModelRunnerEngineKindCloud {
55-
// TODO: Find a more robust solution in Moby-like environments.
56-
_ = setenv("URL", "http://host.docker.internal:"+strconv.Itoa(standalone.DefaultControllerPort)+"/engines/v1/")
54+
} else if kind == desktop.ModelRunnerEngineKindMoby {
55+
// TODO: Use more robust detection in Moby-like environments.
56+
_ = setenv("URL", "http://host.docker.internal:"+strconv.Itoa(standalone.DefaultControllerPortMoby)+"/engines/v1/")
57+
} else if kind == desktop.ModelRunnerEngineKindCloud {
58+
// TODO: Use more robust detection in Cloud environments.
59+
_ = setenv("URL", "http://host.docker.internal:"+strconv.Itoa(standalone.DefaultControllerPortCloud)+"/engines/v1/")
5760
}
5861
return nil
5962
},

commands/install-runner.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ func ensureStandaloneRunnerAvailable(ctx context.Context, printer standalone.Sta
9696
}
9797

9898
// Create the model runner container.
99-
if err := standalone.CreateControllerContainer(ctx, dockerClient, standalone.DefaultControllerPort, gpu, modelStorageVolume, printer); err != nil {
99+
port := uint16(standalone.DefaultControllerPortMoby)
100+
if engineKind == desktop.ModelRunnerEngineKindCloud {
101+
port = standalone.DefaultControllerPortCloud
102+
}
103+
if err := standalone.CreateControllerContainer(ctx, dockerClient, port, gpu, modelStorageVolume, printer); err != nil {
100104
return fmt.Errorf("unable to initialize standalone model runner container: %w", err)
101105
}
102106

@@ -112,18 +116,31 @@ func newInstallRunner() *cobra.Command {
112116
Short: "Install Docker Model Runner",
113117
RunE: func(cmd *cobra.Command, args []string) error {
114118
// Ensure that we're running in a supported model runner context.
115-
if kind := modelRunner.EngineKind(); kind == desktop.ModelRunnerEngineKindDesktop {
119+
engineKind := modelRunner.EngineKind()
120+
if engineKind == desktop.ModelRunnerEngineKindDesktop {
116121
// TODO: We may eventually want to auto-forward this to
117122
// docker desktop enable model-runner, but we should first make
118123
// sure the CLI flags match.
119124
cmd.Println("Standalone installation not supported with Docker Desktop")
120125
cmd.Println("Use `docker desktop enable model-runner` instead")
121126
return nil
122-
} else if kind == desktop.ModelRunnerEngineKindMobyManual {
127+
} else if engineKind == desktop.ModelRunnerEngineKindMobyManual {
123128
cmd.Println("Standalone installation not supported with MODEL_RUNNER_HOST set")
124129
return nil
125130
}
126131

132+
// HACK: If we're in a Cloud context, then we need to use a
133+
// different default port because it conflicts with Docker Desktop's
134+
// default model runner host-side port. Unfortunately we can't make
135+
// the port flag default dynamic (at least not easily) because of
136+
// when context detection happens. So assume that a default value
137+
// indicates that we want the Cloud default port. This is less
138+
// problematic in Cloud since the UX there is mostly invisible.
139+
if engineKind == desktop.ModelRunnerEngineKindCloud &&
140+
port == standalone.DefaultControllerPortMoby {
141+
port = standalone.DefaultControllerPortCloud
142+
}
143+
127144
// Create a Docker client for the active context.
128145
dockerClient, err := desktop.DockerClientForContext(dockerCLI, dockerCLI.CurrentContext())
129146
if err != nil {
@@ -176,7 +193,7 @@ func newInstallRunner() *cobra.Command {
176193
},
177194
ValidArgsFunction: completion.NoComplete,
178195
}
179-
c.Flags().Uint16Var(&port, "port", standalone.DefaultControllerPort,
196+
c.Flags().Uint16Var(&port, "port", standalone.DefaultControllerPortMoby,
180197
"Docker container port for Docker Model Runner")
181198
c.Flags().StringVar(&gpuMode, "gpu", "auto", "Specify GPU support (none|auto|cuda)")
182199
return c

desktop/context.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,16 @@ func DetectContext(cli *command.DockerCli) (*ModelRunnerContext, error) {
159159

160160
// Compute the URL prefix based on the associated engine kind.
161161
var rawURLPrefix string
162-
if kind == ModelRunnerEngineKindMoby || kind == ModelRunnerEngineKindCloud {
163-
rawURLPrefix = "http://localhost:" + strconv.Itoa(int(standalone.DefaultControllerPort))
162+
if kind == ModelRunnerEngineKindMoby {
163+
rawURLPrefix = "http://localhost:" + strconv.Itoa(standalone.DefaultControllerPortMoby)
164+
} else if kind == ModelRunnerEngineKindCloud {
165+
rawURLPrefix = "http://localhost:" + strconv.Itoa(standalone.DefaultControllerPortCloud)
164166
} else if kind == ModelRunnerEngineKindMobyManual {
165167
rawURLPrefix = modelRunnerHost
166168
} else { // ModelRunnerEngineKindDesktop
167169
rawURLPrefix = "http://localhost" + inference.ExperimentalEndpointsPrefix
168170
if treatDesktopAsMoby {
169-
rawURLPrefix = "http://localhost:" + strconv.Itoa(int(standalone.DefaultControllerPort))
171+
rawURLPrefix = "http://localhost:" + strconv.Itoa(standalone.DefaultControllerPortMoby)
170172
}
171173
}
172174
urlPrefix, err := url.Parse(rawURLPrefix)

pkg/standalone/ports.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package standalone
22

3-
// DefaultControllerPort is the default TCP port on which the standalone
4-
// controller will listen for requests.
5-
const DefaultControllerPort = 12434
3+
const (
4+
// DefaultControllerPortMoby is the default TCP port on which the standalone
5+
// controller will listen for requests in Moby environments.
6+
DefaultControllerPortMoby = 12434
7+
// DefaultControllerPortCloud is the default TCP port on which the
8+
// standalone controller will listen for requests in Moby environments.
9+
DefaultControllerPortCloud = 12435
10+
)

0 commit comments

Comments
 (0)