Skip to content

Document new support for WithContainerRunArgs method on container-based resources #707

@DamianEdwards

Description

@DamianEdwards

With dotnet/aspire#2737 we added support for WithContainerRunArgs to Aspire.Hosting. This can be used to pass arguments directly to the container host run command for advanced scenarios like adjusting CPU & memory limits, or enabling GPU access, e.g.:

// Add an ollama container
var ollama = builder.AddContainer("ollama", "ollama/ollama")
    .WithBindMount("ollama", "/root/.ollama")
    .WithBindMount("./ollamaconfig", "/usr/config")
    .WithHttpEndpoint(port: 11434, targetPort: 11434, name: "ollama")
    .WithEntrypoint("/usr/config/entrypoint.sh")
    // Enable GPU support in Docker Desktop, i.e. https://docs.docker.com/desktop/gpu/
    .WithContainerRunArgs("--gpus=all")
    // Enable GPU support in Podman when not using Docker CLI emulation, i.e. https://github.com/containers/podman/issues/19005
    // .WithContainerRunArgs("--device", "nvidia.com/gpu=all")
    ;

Associated WorkItem - 261093

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.Pri1High priority, do before Pri2 and Pri3doc-enhancementImprove the current content [org][type][category]fundamentalsContent related to fundamentals.preview-6Used to track doc updates for preview 6 of .NET Aspire

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions