VolumeDefinition Class
Describes how a volume should be created. Configure an instance and call VolumeDefinition.CreateVolume to obtain a TemporaryVolume.
public sealed class VolumeDefinitionExample
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
| Name | Description |
|---|---|
| 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.csInitializes a new instance of the VolumeDefinition class.
public VolumeDefinition()VolumeDefinition(VolumeDefinition)
VolumeDefinition.csInitializes 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
otherVolumeDefinition- The definition to copy.
Properties
| Name | Description |
|---|---|
| Driver | Gets or sets the volume driver. When null, the runtime uses its default driver. |
| DriverOptions | Gets the driver-specific options. |
| IsReadOnly | Gets a value indicating whether the definition belongs to a volume, in which case it can no longer be changed. |
| Labels | Gets the labels. |
| Name | Gets or sets the volume name. When null, a random name is generated, or a name derived from VolumeDefinition.ReuseId when that is set. |
| ReuseId | Gets or sets an identifier used to reuse an existing volume across runs. When set, the volume is not removed on dispose. |
| Runtime | Gets or sets the container runtime to use. |
Driver
VolumeDefinition.csDriverOptions
VolumeDefinition.csGets the driver-specific options.
public VolumeDriverOptionCollection DriverOptions { get; }Property value
IsReadOnly
VolumeDefinition.csLabels
VolumeDefinition.csGets 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
ReuseId
VolumeDefinition.csRuntime
VolumeDefinition.csGets or sets the container runtime to use.
public ContainerRuntime Runtime { get; set; }Property value
Methods
| Name | Description |
|---|---|
| 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.csCreates 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.