ContainerResourceBuilderExtensions.AddDockerfile 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 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
Path to the Dockerfile relative to the contextPath. Defaults to "Dockerfile" if not specified.
- stage
- String
The stage representing the image to be published in a multi-stage Dockerfile.
Returns
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
The contextPath is relative to the AppHost directory unless it is a fully qualified path. The dockerfilePath is relative to the contextPath unless it is a fully qualified path. If the dockerfilePath is not provided, it defaults to "Dockerfile" in 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.
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();