VolumeDefinition Class

Describes how a volume should be created. Configure an instance and call VolumeDefinition.CreateVolume to obtain a TemporaryVolume.

public sealed class VolumeDefinition

Example

await using var volume = new VolumeDefinition().CreateVolume();

var definition = new ContainerDefinition(ImageSource.FromRegistry("redis:8"));
definition.Mounts.AddVolume(volume, "/data");

await using var container = definition.CreateContainer();
await container.StartAsync();

Constructors

NameDescription
VolumeDefinition()Initializes a new instance of the VolumeDefinition class.
VolumeDefinition(VolumeDefinition)Initializes a new instance of the VolumeDefinition class by deep-copying another definition. The copy can be changed even when other belongs to a volume.

VolumeDefinition overloads

VolumeDefinition()

VolumeDefinition.cs

Initializes a new instance of the VolumeDefinition class.

public VolumeDefinition()

VolumeDefinition(VolumeDefinition)

VolumeDefinition.cs

Initializes a new instance of the VolumeDefinition class by deep-copying another definition. The copy can be changed even when other belongs to a volume.

public VolumeDefinition(VolumeDefinition other)
Parameters
other VolumeDefinition
The definition to copy.

Properties

NameDescription
DriverGets or sets the volume driver. When null, the runtime uses its default driver.
DriverOptionsGets the driver-specific options.
IsReadOnlyGets a value indicating whether the definition belongs to a volume, in which case it can no longer be changed.
LabelsGets the labels.
NameGets or sets the volume name. When null, a random name is generated, or a name derived from VolumeDefinition.ReuseId when that is set.
ReuseIdGets or sets an identifier used to reuse an existing volume across runs. When set, the volume is not removed on dispose.
RuntimeGets or sets the container runtime to use.

Gets or sets the volume driver. When null, the runtime uses its default driver.

public string? Driver { get; set; }

Property value

string?

DriverOptions

VolumeDefinition.cs

Gets the driver-specific options.

public VolumeDriverOptionCollection DriverOptions { get; }

Gets a value indicating whether the definition belongs to a volume, in which case it can no longer be changed.

public bool IsReadOnly { get; }

Property value

bool

Gets the labels.

public ContainerLabelCollection Labels { get; }

Gets or sets the volume name. When null, a random name is generated, or a name derived from VolumeDefinition.ReuseId when that is set.

public string? Name { get; set; }

Property value

string?

Gets or sets an identifier used to reuse an existing volume across runs. When set, the volume is not removed on dispose.

public string? ReuseId { get; set; }

Property value

string?

Gets or sets the container runtime to use.

public ContainerRuntime Runtime { get; set; }

Property value

ContainerRuntime

Methods

NameDescription
CreateVolume()Creates a TemporaryVolume from a deep copy of this definition. Later changes to this definition do not affect the returned volume, and the copy the volume owns cannot be changed.

CreateVolume()

VolumeDefinition.cs

Creates a TemporaryVolume from a deep copy of this definition. Later changes to this definition do not affect the returned volume, and the copy the volume owns cannot be changed.

public TemporaryVolume CreateVolume()

Returns

TemporaryVolume A new volume.