ContainerRuntime Class
Identifies the runtime used to manage containers.
public abstract class ContainerRuntimeProperties
| Name | Description |
|---|---|
| AppleContainer | Use Apple's container CLI (macOS). |
| Auto | Automatically detect an available runtime. |
| Docker | Use the docker CLI. |
| DockerApi | Use the Docker Engine API, over the unix socket or the named pipe of the daemon, without going through the docker CLI. |
| Podman | Use the podman CLI. |
| Wslc | Use the WSL container CLI (wslc, Windows). |
AppleContainer
ContainerRuntime.csUse Apple's container CLI (macOS).
public static ContainerRuntime AppleContainer { get; }Property value
Automatically detect an available runtime.
public static ContainerRuntime Auto { get; }Property value
Docker
ContainerRuntime.csDockerApi
ContainerRuntime.csUse the Docker Engine API, over the unix socket or the named pipe of the daemon, without going through the docker CLI.
public static ContainerRuntime DockerApi { get; }Property value
Podman
ContainerRuntime.csUse the WSL container CLI (wslc, Windows).
public static ContainerRuntime Wslc { get; }Property value
Methods
| Name | Description |
|---|---|
| CleanupAsync(ContainerCleanupOptions, CancellationToken) | Removes the containers, images, volumes and networks this library left behind, for instance by a run that was interrupted before it could dispose them. |
| CleanupAsync(CancellationToken) | Removes the containers, images, volumes and networks this library left behind, for instance by a run that was interrupted before it could dispose them. |
| IsSupportedAsync(CancellationToken) | Determines whether this runtime can be resolved. |
| StartReaperAsync(ContainerReaperOptions, CancellationToken) | Starts a watchdog container that removes the containers, images and volumes created by this process once the process is gone, even when it is killed before it can dispose them. |
| StartReaperAsync(CancellationToken) | Starts a watchdog container that removes the containers, images and volumes created by this process once the process is gone, even when it is killed before it can dispose them. |
| ToString() |
CleanupAsync overloads
CleanupAsync(ContainerCleanupOptions, CancellationToken)
ContainerRuntime.Cleanup.csRemoves the containers, images, volumes and networks this library left behind, for instance by a run that was interrupted before it could dispose them.
net10.0
public Task<ContainerCleanupResult> CleanupAsync(ContainerCleanupOptions options, CancellationToken cancellationToken = default)net11.0
public Task<ContainerCleanupResult> CleanupAsync(ContainerCleanupOptions options, CancellationToken cancellationToken = default)Parameters
optionsContainerCleanupOptions- What to remove. By default, only the resources whose creating process is gone.
cancellationTokenCancellationToken- A cancellation token.
Returns
Task<ContainerCleanupResult> The removed resources.
Exceptions
InvalidOperationException- The runtime is not available.
Remarks
The resources of the current process are never removed, whatever the scope: a cleanup at the beginning of a test run cannot break the containers that run is about to use, nor its reaper.
CleanupAsync(CancellationToken)
ContainerRuntime.Cleanup.csRemoves the containers, images, volumes and networks this library left behind, for instance by a run that was interrupted before it could dispose them.
public Task<ContainerCleanupResult> CleanupAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken- A cancellation token.
Returns
Task<ContainerCleanupResult> The removed resources.
Exceptions
InvalidOperationException- The runtime is not available.
IsSupportedAsync(CancellationToken)
ContainerRuntime.csDetermines whether this runtime can be resolved.
public virtual Task<bool> IsSupportedAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken- A cancellation token.
Returns
Task<bool> true if the runtime executable is available and operational; otherwise, false.
Remarks
The runtime is not considered available until its daemon answers, so the first call runs a command or opens a connection. Concurrent calls share that probe. A success is cached; a failure is not, so a daemon that starts later is still detected.
StartReaperAsync overloads
StartReaperAsync(ContainerReaperOptions, CancellationToken)
ContainerRuntime.Reaper.csStarts a watchdog container that removes the containers, images and volumes created by this process once the process is gone, even when it is killed before it can dispose them.
net10.0
public Task<ContainerReaper> StartReaperAsync(ContainerReaperOptions options, CancellationToken cancellationToken = default)net11.0
public Task<ContainerReaper> StartReaperAsync(ContainerReaperOptions options, CancellationToken cancellationToken = default)Parameters
optionsContainerReaperOptions- The watchdog configuration.
cancellationTokenCancellationToken- A cancellation token.
Returns
Task<ContainerReaper> The watchdog. Keep it alive for as long as the containers it watches, and dispose it to stop it.
Exceptions
NotSupportedException- The runtime does not expose a socket the watchdog can drive.
Remarks
The watchdog only removes the resources this process created; the resources of a run that has a ContainerDefinition.ReuseId are not part of a session and are left alone.
StartReaperAsync(CancellationToken)
ContainerRuntime.Reaper.csStarts a watchdog container that removes the containers, images and volumes created by this process once the process is gone, even when it is killed before it can dispose them.
public Task<ContainerReaper> StartReaperAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken- A cancellation token.
Returns
Task<ContainerReaper> The watchdog. Keep it alive for as long as the containers it watches, and dispose it to stop it.
Exceptions
NotSupportedException- The runtime does not expose a socket the watchdog can drive.