Skip to content

Conversation

ericcurtin
Copy link
Contributor

@ericcurtin ericcurtin commented Oct 11, 2025

To start and stop the docker model runner container.

Summary by Sourcery

Implement start and stop commands for the standalone Docker Model Runner container

New Features:

  • Introduce StartControllerContainer to resume a stopped model runner container
  • Introduce StopControllerContainer to halt a running model runner container
  • Expose these operations via new docker model start and docker model stop CLI subcommands

Documentation:

  • Add YAML reference and Markdown documentation for the docker model start and docker model stop commands

To start and stop the docker model runner container.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
@Copilot Copilot AI review requested due to automatic review settings October 11, 2025 14:49
Copy link
Contributor

sourcery-ai bot commented Oct 11, 2025

Reviewer's Guide

Add standalone start/stop support for the Docker Model Runner container by introducing controller start/stop utilities, registering new CLI commands with context validation, and updating reference documentation.

Sequence diagram for starting the Docker Model Runner container via CLI

sequenceDiagram
    actor User
    participant CLI
    participant "modelRunner"
    participant "desktop"
    participant "standalone"
    participant "DockerClient"
    User->>CLI: Run `docker model start`
    CLI->>modelRunner: EngineKind()
    alt Desktop context
        CLI->>User: Print "Standalone start not supported with Docker Desktop"
        CLI->>User: Print "Use `docker desktop enable model-runner` instead"
    else MobyManual context
        CLI->>User: Print "Standalone start not supported with MODEL_RUNNER_HOST set"
    else Supported context
        CLI->>desktop: DockerClientForContext()
        desktop->>DockerClient: Create client
        CLI->>standalone: StartControllerContainer()
        standalone->>DockerClient: FindControllerContainer()
        standalone->>DockerClient: ensureContainerStarted()
        standalone->>CLI: Print "Model runner container started successfully"
        CLI->>User: Print success message
    end
Loading

Sequence diagram for stopping the Docker Model Runner container via CLI

sequenceDiagram
    actor User
    participant CLI
    participant "modelRunner"
    participant "desktop"
    participant "standalone"
    participant "DockerClient"
    User->>CLI: Run `docker model stop`
    CLI->>modelRunner: EngineKind()
    alt Desktop context
        CLI->>User: Print "Standalone stop not supported with Docker Desktop"
        CLI->>User: Print "Use `docker desktop disable model-runner` instead"
    else MobyManual context
        CLI->>User: Print "Standalone stop not supported with MODEL_RUNNER_HOST set"
    else Supported context
        CLI->>desktop: DockerClientForContext()
        desktop->>DockerClient: Create client
        CLI->>standalone: StopControllerContainer()
        standalone->>DockerClient: FindControllerContainer()
        standalone->>DockerClient: ContainerStop()
        standalone->>CLI: Print "Model runner container stopped successfully"
        CLI->>User: Print success message
    end
Loading

File-Level Changes

Change Details Files
Introduce standalone container start and stop functions
  • Added StartControllerContainer to locate and start the controller container
  • Added StopControllerContainer to locate and stop the controller container with timeout
  • Utilized FindControllerContainer, ensureContainerStarted, and dockerClient.ContainerStop APIs
  • Emitted status messages via StatusPrinter
cmd/cli/pkg/standalone/containers.go
Register new start and stop commands in root CLI
  • Added newStartRunner and newStopRunner to the root command list
cmd/cli/commands/root.go
Implement start and stop subcommands with context checks
  • Created start-runner.go to validate engine context and invoke StartControllerContainer
  • Created stop-runner.go to validate engine context and invoke StopControllerContainer
  • Handled unsupported contexts for Docker Desktop and manual daemons
cmd/cli/commands/start-runner.go
cmd/cli/commands/stop-runner.go
Add CLI reference documentation for start and stop commands
  • Added YAML definitions for docker_model_start and docker_model_stop
  • Added markdown docs model_start.md and model_stop.md with descriptions and usage
cmd/cli/docs/reference/docker_model_start.yaml
cmd/cli/docs/reference/docker_model_stop.yaml
cmd/cli/docs/reference/model_start.md
cmd/cli/docs/reference/model_stop.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

Summary of Changes

Hello @ericcurtin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Docker Model Runner CLI by adding dedicated commands to start and stop the model runner container. These new commands provide users with direct control over the container's state, particularly in standalone environments where Docker Desktop or a manually configured host is not in use. The changes include the command definitions, the underlying functions for container interaction, and updated documentation to reflect the new functionality.

Highlights

  • New CLI Commands: Introduced docker model start and docker model stop commands to explicitly manage the Docker Model Runner container lifecycle.
  • Container Management Logic: Implemented the core logic for starting and stopping the model runner container within the standalone package, including checks for unsupported engine kinds (Docker Desktop, Moby Manual with MODEL_RUNNER_HOST).
  • Documentation Updates: Added comprehensive documentation for the new start and stop commands, including YAML reference files and Markdown descriptions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Docker CLI commands to start and stop the model runner container, providing basic lifecycle management functionality.

  • Implements StartControllerContainer and StopControllerContainer functions with container lookup and state management
  • Creates new CLI commands docker model start and docker model stop with proper error handling for unsupported contexts
  • Adds comprehensive documentation files for both commands

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cmd/cli/pkg/standalone/containers.go Adds container start/stop functions with proper error handling and status reporting
cmd/cli/commands/start-runner.go Implements CLI command for starting model runner containers
cmd/cli/commands/stop-runner.go Implements CLI command for stopping model runner containers
cmd/cli/commands/root.go Registers new start and stop commands with the CLI
cmd/cli/docs/reference/model_start.md Documentation for the start command
cmd/cli/docs/reference/model_stop.md Documentation for the stop command
cmd/cli/docs/reference/docker_model_start.yaml YAML metadata for start command documentation
cmd/cli/docs/reference/docker_model_stop.yaml YAML metadata for stop command documentation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces docker model start and docker model stop commands to manage the lifecycle of the Docker Model Runner container. The implementation adds new cobra commands, corresponding business logic in the standalone package, and documentation.

My review has identified a critical issue in the start command's implementation that will prevent it from working as intended. There's also a high-severity issue with the stop command regarding idempotency and side effects. Additionally, I've provided some medium-severity suggestions to improve code quality and maintainability in the new command files and the container management logic.

Comment on lines +353 to +359
containerID, containerName, _, err := FindControllerContainer(ctx, dockerClient)
if err != nil {
return fmt.Errorf("unable to find model runner container: %w", err)
}
if containerID == "" {
return errors.New("model runner container not found")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The StartControllerContainer function is currently implemented in a way that will prevent it from ever starting a stopped container. It calls FindControllerContainer, which is designed to find running containers. Critically, FindControllerContainer first prunes (removes with docker rm) any stopped controller containers. This means a stopped container will be removed instead of started, and the command will always fail with "model runner container not found".

To fix this, StartControllerContainer should implement its own logic to find the container. It should list all containers (including stopped ones) using client.ContainerList with All: true and the appropriate label filters. Then, it should check the container's state. If it's already running, it can print a message and return. If it's stopped, it should start it. This function should not call FindControllerContainer.

Comment on lines +378 to +384
containerID, containerName, _, err := FindControllerContainer(ctx, dockerClient)
if err != nil {
return fmt.Errorf("unable to find model runner container: %w", err)
}
if containerID == "" {
return errors.New("model runner container not found")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The stop command should be idempotent, meaning it should succeed even if the container is already stopped. Currently, it will return a "model runner container not found" error in that case.

Furthermore, this function calls FindControllerContainer, which has a side effect of pruning (removing) any stopped controller containers. A stop command should not remove containers.

To address these issues, StopControllerContainer should not use FindControllerContainer. Instead, it should list running containers with the correct labels. If a running container is found, it should be stopped. If no running container is found, the function should succeed without error, as the desired state (stopped) is already achieved.

Comment on lines +19 to +26
if kind := modelRunner.EngineKind(); kind == types.ModelRunnerEngineKindDesktop {
cmd.Println("Standalone start not supported with Docker Desktop")
cmd.Println("Use `docker desktop enable model-runner` instead")
return nil
} else if kind == types.ModelRunnerEngineKindMobyManual {
cmd.Println("Standalone start not supported with MODEL_RUNNER_HOST set")
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This if-else if chain can be refactored into a switch statement for better readability and maintainability, especially if more engine kinds are added in the future.

Additionally, messages that inform the user why a command is not being executed should be printed to stderr rather than stdout. You can use cmd.PrintErrln() for this purpose.

Suggested change
if kind := modelRunner.EngineKind(); kind == types.ModelRunnerEngineKindDesktop {
cmd.Println("Standalone start not supported with Docker Desktop")
cmd.Println("Use `docker desktop enable model-runner` instead")
return nil
} else if kind == types.ModelRunnerEngineKindMobyManual {
cmd.Println("Standalone start not supported with MODEL_RUNNER_HOST set")
return nil
}
switch modelRunner.EngineKind() {
case types.ModelRunnerEngineKindDesktop:
cmd.PrintErrln("Standalone start not supported with Docker Desktop\nUse `docker desktop enable model-runner` instead")
return nil
case types.ModelRunnerEngineKindMobyManual:
cmd.PrintErrln("Standalone start not supported with MODEL_RUNNER_HOST set")
return nil
}

Comment on lines +19 to +26
if kind := modelRunner.EngineKind(); kind == types.ModelRunnerEngineKindDesktop {
cmd.Println("Standalone stop not supported with Docker Desktop")
cmd.Println("Use `docker desktop disable model-runner` instead")
return nil
} else if kind == types.ModelRunnerEngineKindMobyManual {
cmd.Println("Standalone stop not supported with MODEL_RUNNER_HOST set")
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This if-else if chain can be refactored into a switch statement for better readability and maintainability, especially if more engine kinds are added in the future.

Additionally, messages that inform the user why a command is not being executed should be printed to stderr rather than stdout. You can use cmd.PrintErrln() for this purpose.

Suggested change
if kind := modelRunner.EngineKind(); kind == types.ModelRunnerEngineKindDesktop {
cmd.Println("Standalone stop not supported with Docker Desktop")
cmd.Println("Use `docker desktop disable model-runner` instead")
return nil
} else if kind == types.ModelRunnerEngineKindMobyManual {
cmd.Println("Standalone stop not supported with MODEL_RUNNER_HOST set")
return nil
}
switch modelRunner.EngineKind() {
case types.ModelRunnerEngineKindDesktop:
cmd.PrintErrln("Standalone stop not supported with Docker Desktop\nUse `docker desktop disable model-runner` instead")
return nil
case types.ModelRunnerEngineKindMobyManual:
cmd.PrintErrln("Standalone stop not supported with MODEL_RUNNER_HOST set")
return nil
}

} else {
printer.Printf("Stopping model runner container %s...\n", containerID[:12])
}
stopTimeout := 10 // seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The timeout value 10 is a magic number. It's better to define it as a named constant at the package level (e.g., const defaultStopTimeoutSeconds = 10) to improve readability and maintainability. The comment // seconds is helpful, but a constant name would be self-documenting.

Copy link
Contributor

@doringeman doringeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it supposed to work to docker model stop + docker model start and have the same container back up?

@ericcurtin
Copy link
Contributor Author

@doringeman start/stop is supposed to be like install or uninstall without:

docker pull

and

docker rmi -f

if that makes sense, this is incomplete though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants