ContainerResourceBuilderExtensions.WithBindMount<T> Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds a bind mount to a container resource.
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithBindMount<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string source, string target, bool isReadOnly = false) where T : Aspire.Hosting.ApplicationModel.ContainerResource;
static member WithBindMount : 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 WithBindMount(Of T As ContainerResource) (builder As IResourceBuilder(Of T), source 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.
- source
- String
The source path of the mount. This is the path to the file or directory on the host, relative to the app host project directory.
- target
- String
The target path where the file or directory is mounted in the container.
- isReadOnly
- Boolean
A flag that indicates if this is a read-only mount.
Returns
The IResourceBuilder<T>.
Examples
Adds a bind mount that will mount the config
directory in the app host project directory, to the container's file system at the path /database/config
,
and mark it read-only so that the container cannot modify it:
var builder = DistributedApplication.CreateBuilder(args);
builder.AddContainer("mycontainer", "myimage")
.WithBindMount("./config", "/database/config", isReadOnly: true);
builder.Build().Run();
Adds a bind mount that will mount the init.sh
file from a directory outside the app host project directory, to the container's file system at the path /usr/config/initialize.sh
,
and mark it read-only so that the container cannot modify it:
var builder = DistributedApplication.CreateBuilder(args);
builder.AddContainer("mycontainer", "myimage")
.WithBindMount("../containerconfig/scripts/init.sh", "/usr/config/initialize.sh", isReadOnly: true);
builder.Build().Run();
Remarks
Bind mounts are used to mount files or directories from the host file-system into the container. If the host doesn't require access to the files, consider using volumes instead via WithVolume<T>(IResourceBuilder<T>, String, String, Boolean).
The source
path specifies the path of the file or directory on the host that will be mounted in the container. If the path is not absolute, it will be evaluated relative to the app host project directory path.
The target
path specifies the path the file or directory will be mounted inside the container's file system.