ContainerResourceBuilderExtensions.AddDockerfile Method

Definition

Adds a Dockerfile to the application model that can be treated like a container resource.

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

Parameters

name
String

The name of the resource.

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 based on a Dockerfile in the context path path/to/context.

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

Remarks

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 AddDockerfile(IDistributedApplicationBuilder, String, String, String, String) method results in an additional attribute being added to the `container.v1` resource type which contains the configuration necessary to allow the deployment tool to build the container image prior to deployment.

Applies to