Skip to content

Commit 4ebad0e

Browse files
fix(containers): improve port binding error message for clarity (#596)
* fix(containers): improve port binding error message for clarity * Update cmd/cli/pkg/standalone/containers.go Co-authored-by: Dorin-Andrei Geman <dorin.geman@docker.com> --------- Co-authored-by: Dorin-Andrei Geman <dorin.geman@docker.com>
1 parent 7dda330 commit 4ebad0e

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

cmd/cli/pkg/standalone/containers.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ type TLSOptions struct {
289289
// tlsCertContainerPath is the path where TLS certificates will be mounted in the container.
290290
const tlsCertContainerPath = "/etc/model-runner/certs"
291291

292+
// isPortBindingError checks if the error indicates a port is already in use
293+
func isPortBindingError(err error) bool {
294+
if err == nil {
295+
return false
296+
}
297+
errStr := err.Error()
298+
return strings.Contains(errStr, "ports are not available") &&
299+
(strings.Contains(errStr, "address already in use") ||
300+
strings.Contains(errStr, "Only one usage of each socket address"))
301+
}
302+
292303
// CreateControllerContainer creates and starts a controller container.
293304
func CreateControllerContainer(ctx context.Context, dockerClient *client.Client, port uint16, host string, environment string, doNotTrack bool, gpu gpupkg.GPUSupport, backend string, modelStorageVolume string, printer StatusPrinter, engineKind types.ModelRunnerEngineKind, debug bool, vllmOnWSL bool, proxyCert string, tlsOpts TLSOptions) error {
294305
imageName := controllerImageName(gpu, backend)
@@ -554,6 +565,9 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
554565
if created {
555566
_ = dockerClient.ContainerRemove(ctx, resp.ID, container.RemoveOptions{Force: true})
556567
}
568+
if isPortBindingError(err) {
569+
return fmt.Errorf("failed to start container %s: %w\n\nThe port may already be in use by Docker Desktop's Model Runner.\nTry running: docker desktop disable model-runner", controllerContainerName, err)
570+
}
557571
return fmt.Errorf("failed to start container %s: %w", controllerContainerName, err)
558572
}
559573

0 commit comments

Comments
 (0)