ContainerResourceBuilderExtensions.WithDockerfileBuilder 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.
Overloads
| WithDockerfileBuilder<T>(IResourceBuilder<T>, String, Action<DockerfileBuilderCallbackContext>, String) |
Builds the specified container image from a Dockerfile generated by a synchronous callback using the DockerfileBuilder API. |
| WithDockerfileBuilder<T>(IResourceBuilder<T>, String, Func<DockerfileBuilderCallbackContext,Task>, String) |
Builds the specified container image from a Dockerfile generated by a callback using the DockerfileBuilder API. |
WithDockerfileBuilder<T>(IResourceBuilder<T>, String, Action<DockerfileBuilderCallbackContext>, String)
Builds the specified container image from a Dockerfile generated by a synchronous callback using the DockerfileBuilder API.
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithDockerfileBuilder<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string contextPath, Action<Aspire.Hosting.ApplicationModel.DockerfileBuilderCallbackContext> callback, string? stage = default) where T : Aspire.Hosting.ApplicationModel.ContainerResource;
static member WithDockerfileBuilder : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> * string * Action<Aspire.Hosting.ApplicationModel.DockerfileBuilderCallbackContext> * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)
<Extension()>
Public Function WithDockerfileBuilder(Of T As ContainerResource) (builder As IResourceBuilder(Of T), contextPath As String, callback As Action(Of DockerfileBuilderCallbackContext), Optional stage As String = Nothing) As IResourceBuilder(Of T)
Type Parameters
- T
Type parameter specifying any type derived from ContainerResource.
Parameters
- builder
- IResourceBuilder<T>
The IResourceBuilder<T>.
- contextPath
- String
Path to be used as the context for the container image build.
- callback
- Action<DockerfileBuilderCallbackContext>
A synchronous callback that uses the DockerfileBuilder API to construct the Dockerfile.
- stage
- String
The stage representing the image to be published in a multi-stage Dockerfile.
Returns
The IResourceBuilder<T>.
Remarks
This method provides a programmatic way to build Dockerfiles using the DockerfileBuilder API instead of string manipulation. Callbacks can be composed by calling this method multiple times - each callback will be invoked in order to build up the final Dockerfile.
The contextPath is relative to the AppHost directory unless it is fully qualified.
var builder = DistributedApplication.CreateBuilder(args);
builder.AddContainer("mycontainer", "myimage")
.WithDockerfileBuilder("path/to/context", context =>
{
context.Builder.From("node:18")
.WorkDir("/app")
.Copy("package*.json", "./")
.Run("npm ci");
});
builder.Build().Run();
Applies to
WithDockerfileBuilder<T>(IResourceBuilder<T>, String, Func<DockerfileBuilderCallbackContext,Task>, String)
Builds the specified container image from a Dockerfile generated by a callback using the DockerfileBuilder API.
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithDockerfileBuilder<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string contextPath, Func<Aspire.Hosting.ApplicationModel.DockerfileBuilderCallbackContext,System.Threading.Tasks.Task> callback, string? stage = default) where T : Aspire.Hosting.ApplicationModel.ContainerResource;
static member WithDockerfileBuilder : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> * string * Func<Aspire.Hosting.ApplicationModel.DockerfileBuilderCallbackContext, System.Threading.Tasks.Task> * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)
<Extension()>
Public Function WithDockerfileBuilder(Of T As ContainerResource) (builder As IResourceBuilder(Of T), contextPath As String, callback As Func(Of DockerfileBuilderCallbackContext, Task), Optional stage As String = Nothing) As IResourceBuilder(Of T)
Type Parameters
- T
Type parameter specifying any type derived from ContainerResource.
Parameters
- builder
- IResourceBuilder<T>
The IResourceBuilder<T>.
- contextPath
- String
Path to be used as the context for the container image build.
- callback
- Func<DockerfileBuilderCallbackContext,Task>
A callback that uses the DockerfileBuilder API to construct the Dockerfile.
- stage
- String
The stage representing the image to be published in a multi-stage Dockerfile.
Returns
The IResourceBuilder<T>.
Remarks
This method provides a programmatic way to build Dockerfiles using the DockerfileBuilder API instead of string manipulation. Callbacks can be composed by calling this method multiple times - each callback will be invoked in order to build up the final Dockerfile.
The contextPath is relative to the AppHost directory unless it is fully qualified.
var builder = DistributedApplication.CreateBuilder(args);
builder.AddContainer("mycontainer", "myimage")
.WithDockerfileBuilder("path/to/context", context =>
{
context.Builder.From("alpine:latest")
.WorkDir("/app")
.Run("apk add curl")
.Copy(".", ".")
.Cmd(["./myapp"]);
return Task.CompletedTask;
});
builder.Build().Run();