ContainerRuntime Class

Identifies the runtime used to manage containers.

public abstract class ContainerRuntime

Properties

NameDescription
AppleContainerUse Apple's container CLI (macOS).
AutoAutomatically detect an available runtime.
DockerUse the docker CLI.
DockerApiUse the Docker Engine API, over the unix socket or the named pipe of the daemon, without going through the docker CLI.
PodmanUse the podman CLI.
WslcUse the WSL container CLI (wslc, Windows).

AppleContainer

ContainerRuntime.cs

Use Apple's container CLI (macOS).

public static ContainerRuntime AppleContainer { get; }

Property value

ContainerRuntime

Automatically detect an available runtime.

public static ContainerRuntime Auto { get; }

Property value

ContainerRuntime

Use the docker CLI.

public static ContainerRuntime Docker { get; }

Property value

ContainerRuntime

Use 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

ContainerRuntime

Use the podman CLI.

public static ContainerRuntime Podman { get; }

Property value

ContainerRuntime

Use the WSL container CLI (wslc, Windows).

public static ContainerRuntime Wslc { get; }

Property value

ContainerRuntime

Methods

NameDescription
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.cs

Removes 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
options ContainerCleanupOptions
What to remove. By default, only the resources whose creating process is gone.
cancellationToken CancellationToken
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.cs

Removes 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
cancellationToken CancellationToken
A cancellation token.
Returns

Task<ContainerCleanupResult> The removed resources.

Exceptions
InvalidOperationException
The runtime is not available.

IsSupportedAsync(CancellationToken)

ContainerRuntime.cs

Determines whether this runtime can be resolved.

public virtual Task<bool> IsSupportedAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken
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.cs

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.

net10.0

public Task<ContainerReaper> StartReaperAsync(ContainerReaperOptions options, CancellationToken cancellationToken = default)

net11.0

public Task<ContainerReaper> StartReaperAsync(ContainerReaperOptions options, CancellationToken cancellationToken = default)
Parameters
options ContainerReaperOptions
The watchdog configuration.
cancellationToken CancellationToken
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.cs

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.

public Task<ContainerReaper> StartReaperAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken CancellationToken
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.
public override string ToString()

Returns

string

No documentation is available.