TemporaryVolume Class

A temporary volume created from a VolumeDefinition. Dispose the instance to remove the volume.

public sealed class TemporaryVolume : IAsyncDisposable

Remarks

Disposing only removes the volume when this instance created it and VolumeDefinition.ReuseId is not set. A volume that already existed when TemporaryVolume.EnsureCreatedAsync ran is adopted and left behind, so pointing a definition at an existing volume never destroys it.

Implements

Properties

NameDescription
DefinitionGets the definition owned by this volume. It is read-only.
NameGets the volume name.
RuntimeGets the container runtime in use.

Gets the definition owned by this volume. It is read-only.

public VolumeDefinition Definition { get; }

Property value

VolumeDefinition

Gets the volume name.

public string Name { get; }

Property value

string

Gets the container runtime in use.

public ContainerRuntime Runtime { get; }

Property value

ContainerRuntime

Methods

NameDescription
DeleteAsync(CancellationToken)Removes the volume.
DisposeAsync()Removes the volume when this instance created it and VolumeDefinition.ReuseId is not set. Cleanup is best-effort, bounded in time, and never throws.
EnsureCreatedAsync(CancellationToken)Creates the volume if it does not exist yet. An existing volume is adopted instead, and is not removed on dispose.
ExistsAsync(CancellationToken)Determines whether the volume exists.

DeleteAsync(CancellationToken)

TemporaryVolume.cs

Removes the volume.

net10.0

public Task DeleteAsync(CancellationToken cancellationToken = default)

net11.0

public Task DeleteAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken
A cancellation token.

Returns

Task A task that completes once the volume is removed.

Exceptions

InvalidOperationException
The volume could not be removed, for instance because a container still uses it.

DisposeAsync()

TemporaryVolume.cs

Removes the volume when this instance created it and VolumeDefinition.ReuseId is not set. Cleanup is best-effort, bounded in time, and never throws.

net10.0

public ValueTask DisposeAsync()

net11.0

public ValueTask DisposeAsync()

Returns

ValueTask A task that completes once cleanup finishes.

EnsureCreatedAsync(CancellationToken)

TemporaryVolume.cs

Creates the volume if it does not exist yet. An existing volume is adopted instead, and is not removed on dispose.

net10.0

public Task EnsureCreatedAsync(CancellationToken cancellationToken = default)

net11.0

public Task EnsureCreatedAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken
A cancellation token.

Returns

Task A task that completes once the volume exists.

ExistsAsync(CancellationToken)

TemporaryVolume.cs

Determines whether the volume exists.

net10.0

public Task<bool> ExistsAsync(CancellationToken cancellationToken = default)

net11.0

public Task<bool> ExistsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken
A cancellation token.

Returns

Task<bool> true if the volume exists; otherwise, false.