次の方法で共有


ContainerResourceBuilderExtensions.WithDockerfile<T> Method

Definition

Causes .NET Aspire to build the specified container image from a Dockerfile.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithDockerfile<T> (this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string contextPath, string? dockerfilePath = default, string? stage = default) where T : Aspire.Hosting.ApplicationModel.ContainerResource;
static member WithDockerfile : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> * string * string * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)
<Extension()>
Public Function WithDockerfile(Of T As ContainerResource) (builder As IResourceBuilder(Of T), contextPath As String, Optional dockerfilePath As String = Nothing, Optional stage As String = Nothing) As IResourceBuilder(Of T)

Type Parameters

T

Type parameter specifying any type derived from ContainerResource/

Parameters

contextPath
String

Path to be used as the context for the container image build.

dockerfilePath
String

Override path for the Dockerfile if it is not in the contextPath.

stage
String

The stage representing the image to be published in a multi-stage Dockerfile.

Returns

A IResourceBuilder<T>.

Examples

Creates a container called mycontainer with an image called myimage.

var builder = DistributedApplication.CreateBuilder(args);
builder.AddContainer("mycontainer", "myimage")
       .WithDockerfile("path/to/context");
builder.Build().Run();

Remarks

When this method is called an annotation is added to the ContainerResource that specifies the context path and Dockerfile path to be used when building the container image. These details are then used by the orchestrator to build the image before using that image to start the container.

Both the contextPath and dockerfilePath are relative to the AppHost directory unless they are fully qualified. If the dockerfilePath is not provided, the path is assumed to be Dockerfile relative to the contextPath.

When generating the manifest for deployment tools, the WithDockerfile<T>(IResourceBuilder<T>, String, String, String) method results in an additional attribute being added to the `container.v0` resource type which contains the configuration necessary to allow the deployment tool to build the container image prior to deployment.

Applies to