Share via


ContainerResourceBuilderExtensions.WithVolume Method

Definition

Overloads

WithVolume<T>(IResourceBuilder<T>, String)

Adds an anonymous volume to a container resource.

WithVolume<T>(IResourceBuilder<T>, String, String, Boolean)

Adds a volume to a container resource.

WithVolume<T>(IResourceBuilder<T>, String)

Source:
ContainerResourceBuilderExtensions.cs
Source:
ContainerResourceBuilderExtensions.cs
Source:
ContainerResourceBuilderExtensions.cs
Source:
ContainerResourceBuilderExtensions.cs

Adds an anonymous volume to a container resource.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithVolume<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string target) where T : Aspire.Hosting.ApplicationModel.ContainerResource;
static member WithVolume : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)
<Extension()>
Public Function WithVolume(Of T As ContainerResource) (builder As IResourceBuilder(Of T), target As String) As IResourceBuilder(Of T)

Type Parameters

T

The resource type.

Parameters

builder
IResourceBuilder<T>

The resource builder.

target
String

The target path where the volume is mounted in the container.

Returns

The IResourceBuilder<T>.

Examples

Adds an anonymous volume that will be mounted in the container's file system at the path /usr/data:

var builder = DistributedApplication.CreateBuilder(args);

builder.AddContainer("mycontainer", "myimage")
       .WithVolume("/usr/data");

builder.Build().Run();

Remarks

Volumes are used to persist file-based data generated by and used by the container. They are managed by the container runtime and can be shared among multiple containers. They are not shared with the host's file-system. To mount files from the host inside the container, call WithBindMount<T>(IResourceBuilder<T>, String, String, Boolean).

This overload will create an "anonymous volume" and will be given a random name by the container runtime. To share a volume between multiple containers, call WithVolume<T>(IResourceBuilder<T>, String, String, Boolean) and specify the same value for name.

The target path specifies the path the volume will be mounted inside the container's file system.

Applies to

WithVolume<T>(IResourceBuilder<T>, String, String, Boolean)

Source:
ContainerResourceBuilderExtensions.cs
Source:
ContainerResourceBuilderExtensions.cs
Source:
ContainerResourceBuilderExtensions.cs
Source:
ContainerResourceBuilderExtensions.cs

Adds a volume to a container resource.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithVolume<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string name, string target, bool isReadOnly = false) where T : Aspire.Hosting.ApplicationModel.ContainerResource;
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithVolume<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string? name, string target, bool isReadOnly = false) where T : Aspire.Hosting.ApplicationModel.ContainerResource;
static member WithVolume : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> * string * string * bool -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)
<Extension()>
Public Function WithVolume(Of T As ContainerResource) (builder As IResourceBuilder(Of T), name As String, target As String, Optional isReadOnly As Boolean = false) As IResourceBuilder(Of T)

Type Parameters

T

The resource type.

Parameters

builder
IResourceBuilder<T>

The resource builder.

name
String

The name of the volume.

target
String

The target path where the volume is mounted in the container.

isReadOnly
Boolean

A flag that indicates if the volume should be mounted as read-only.

Returns

The IResourceBuilder<T>.

Examples

Adds a volume named data that will be mounted in the container's file system at the path /usr/data:

var builder = DistributedApplication.CreateBuilder(args);

builder.AddContainer("mycontainer", "myimage")
       .WithVolume("data", "/usr/data");

builder.Build().Run();

Remarks

Volumes are used to persist file-based data generated by and used by the container. They are managed by the container runtime and can be shared among multiple containers. They are not shared with the host's file-system. To mount files from the host inside the container, call WithBindMount<T>(IResourceBuilder<T>, String, String, Boolean).

If a value for the name of the volume is not provided, the volume is created as an "anonymous volume" and will be given a random name by the container runtime. To share a volume between multiple containers, specify the same name.

The target path specifies the path the volume will be mounted inside the container's file system.

Applies to