Skip to content

Commit 105a932

Browse files
authored
Merge pull request #311 from doringeman/docker-rootless
fix(standalone): skip bridge gateway binding for rootless Docker
2 parents a586423 + d497a24 commit 105a932

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

cmd/cli/pkg/standalone/containers.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,21 @@ func ensureContainerStarted(ctx context.Context, dockerClient client.ContainerAP
217217
return errors.New("timed out")
218218
}
219219

220+
// isRootless detects if Docker is running in rootless mode.
221+
func isRootless(ctx context.Context, dockerClient *client.Client) bool {
222+
info, err := dockerClient.Info(ctx)
223+
if err != nil {
224+
// If we can't get Docker info, assume it's not rootless to preserve old behavior.
225+
return false
226+
}
227+
for _, opt := range info.SecurityOptions {
228+
if strings.Contains(opt, "rootless") {
229+
return true
230+
}
231+
}
232+
return false
233+
}
234+
220235
// CreateControllerContainer creates and starts a controller container.
221236
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 {
222237
imageName := controllerImageName(gpu)
@@ -230,7 +245,7 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
230245
if doNotTrack {
231246
env = append(env, "DO_NOT_TRACK=1")
232247
}
233-
248+
234249
// Pass proxy environment variables to the container if they are set
235250
proxyEnvVars := []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY", "http_proxy", "https_proxy", "no_proxy"}
236251
for _, proxyVar := range proxyEnvVars {
@@ -264,8 +279,8 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
264279
portBindings := []nat.PortBinding{{HostIP: host, HostPort: portStr}}
265280
if os.Getenv("_MODEL_RUNNER_TREAT_DESKTOP_AS_MOBY") != "1" {
266281
// Don't bind the bridge gateway IP if we're treating Docker Desktop as Moby.
267-
// Only add bridge gateway IP binding if host is 127.0.0.1
268-
if host == "127.0.0.1" {
282+
// Only add bridge gateway IP binding if host is 127.0.0.1 and not in rootless mode
283+
if host == "127.0.0.1" && !isRootless(ctx, dockerClient) {
269284
if bridgeGatewayIP, err := determineBridgeGatewayIP(ctx, dockerClient); err == nil && bridgeGatewayIP != "" {
270285
portBindings = append(portBindings, nat.PortBinding{HostIP: bridgeGatewayIP, HostPort: portStr})
271286
}

0 commit comments

Comments
 (0)