Skip to content

Commit ac06734

Browse files
Copilotericcurtin
andcommitted
Add --host flag to docker model install-runner command
Co-authored-by: ericcurtin <1694275+ericcurtin@users.noreply.github.com>
1 parent 6f519ed commit ac06734

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

cmd/cli/commands/install-runner.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,13 @@ func ensureStandaloneRunnerAvailable(ctx context.Context, printer standalone.Sta
127127

128128
// Create the model runner container.
129129
port := uint16(standalone.DefaultControllerPortMoby)
130+
host := "127.0.0.1"
130131
environment := "moby"
131132
if engineKind == types.ModelRunnerEngineKindCloud {
132133
port = standalone.DefaultControllerPortCloud
133134
environment = "cloud"
134135
}
135-
if err := standalone.CreateControllerContainer(ctx, dockerClient, port, environment, false, gpu, modelStorageVolume, printer, engineKind); err != nil {
136+
if err := standalone.CreateControllerContainer(ctx, dockerClient, port, host, environment, false, gpu, modelStorageVolume, printer, engineKind); err != nil {
136137
return nil, fmt.Errorf("unable to initialize standalone model runner container: %w", err)
137138
}
138139

@@ -159,6 +160,7 @@ func ensureStandaloneRunnerAvailable(ctx context.Context, printer standalone.Sta
159160

160161
func newInstallRunner() *cobra.Command {
161162
var port uint16
163+
var host string
162164
var gpuMode string
163165
var doNotTrack bool
164166
c := &cobra.Command{
@@ -245,7 +247,7 @@ func newInstallRunner() *cobra.Command {
245247
return fmt.Errorf("unable to initialize standalone model storage: %w", err)
246248
}
247249
// Create the model runner container.
248-
if err := standalone.CreateControllerContainer(cmd.Context(), dockerClient, port, environment, doNotTrack, gpu, modelStorageVolume, cmd, engineKind); err != nil {
250+
if err := standalone.CreateControllerContainer(cmd.Context(), dockerClient, port, host, environment, doNotTrack, gpu, modelStorageVolume, cmd, engineKind); err != nil {
249251
return fmt.Errorf("unable to initialize standalone model runner container: %w", err)
250252
}
251253

@@ -256,6 +258,7 @@ func newInstallRunner() *cobra.Command {
256258
}
257259
c.Flags().Uint16Var(&port, "port", 0,
258260
"Docker container port for Docker Model Runner (default: 12434 for Docker CE, 12435 for Cloud mode)")
261+
c.Flags().StringVar(&host, "host", "127.0.0.1", "Host address to bind Docker Model Runner")
259262
c.Flags().StringVar(&gpuMode, "gpu", "auto", "Specify GPU support (none|auto|cuda)")
260263
c.Flags().BoolVar(&doNotTrack, "do-not-track", false, "Do not track models usage in Docker Model Runner")
261264
return c

cmd/cli/docs/reference/model_install-runner.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ Install Docker Model Runner (Docker Engine only)
55

66
### Options
77

8-
| Name | Type | Default | Description |
9-
|:-----------------|:---------|:--------|:---------------------------------------------------------------------------------------------------|
10-
| `--do-not-track` | `bool` | | Do not track models usage in Docker Model Runner |
11-
| `--gpu` | `string` | `auto` | Specify GPU support (none\|auto\|cuda) |
12-
| `--port` | `uint16` | `0` | Docker container port for Docker Model Runner (default: 12434 for Docker CE, 12435 for Cloud mode) |
8+
| Name | Type | Default | Description |
9+
|:-----------------|:---------|:------------|:---------------------------------------------------------------------------------------------------|
10+
| `--do-not-track` | `bool` | | Do not track models usage in Docker Model Runner |
11+
| `--gpu` | `string` | `auto` | Specify GPU support (none\|auto\|cuda) |
12+
| `--host` | `string` | `127.0.0.1` | Host address to bind Docker Model Runner |
13+
| `--port` | `uint16` | `0` | Docker container port for Docker Model Runner (default: 12434 for Docker CE, 12435 for Cloud mode) |
1314

1415

1516
<!---MARKER_GEN_END-->

cmd/cli/pkg/standalone/containers.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func ensureContainerStarted(ctx context.Context, dockerClient client.ContainerAP
218218
}
219219

220220
// CreateControllerContainer creates and starts a controller container.
221-
func CreateControllerContainer(ctx context.Context, dockerClient *client.Client, port uint16, environment string, doNotTrack bool, gpu gpupkg.GPUSupport, modelStorageVolume string, printer StatusPrinter, engineKind types.ModelRunnerEngineKind) error {
221+
func CreateControllerContainer(ctx context.Context, dockerClient *client.Client, port uint16, host string, environment string, doNotTrack bool, gpu gpupkg.GPUSupport, modelStorageVolume string, printer StatusPrinter, engineKind types.ModelRunnerEngineKind) error {
222222
// Determine the target image.
223223
var imageName string
224224
switch gpu {
@@ -260,11 +260,14 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
260260
Name: "always",
261261
},
262262
}
263-
portBindings := []nat.PortBinding{{HostIP: "127.0.0.1", HostPort: portStr}}
263+
portBindings := []nat.PortBinding{{HostIP: host, HostPort: portStr}}
264264
if os.Getenv("_MODEL_RUNNER_TREAT_DESKTOP_AS_MOBY") != "1" {
265265
// Don't bind the bridge gateway IP if we're treating Docker Desktop as Moby.
266-
if bridgeGatewayIP, err := determineBridgeGatewayIP(ctx, dockerClient); err == nil && bridgeGatewayIP != "" {
267-
portBindings = append(portBindings, nat.PortBinding{HostIP: bridgeGatewayIP, HostPort: portStr})
266+
// Only add bridge gateway IP binding if host is 127.0.0.1
267+
if host == "127.0.0.1" {
268+
if bridgeGatewayIP, err := determineBridgeGatewayIP(ctx, dockerClient); err == nil && bridgeGatewayIP != "" {
269+
portBindings = append(portBindings, nat.PortBinding{HostIP: bridgeGatewayIP, HostPort: portStr})
270+
}
268271
}
269272
}
270273
hostConfig.PortBindings = nat.PortMap{

0 commit comments

Comments
 (0)