ContainerResourceBuilderExtensions.WithDockerfileBaseImage<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.
Configures custom base images for generated Dockerfiles.
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithDockerfileBaseImage<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string? buildImage = default, string? runtimeImage = default) where T : Aspire.Hosting.ApplicationModel.IResource;
static member WithDockerfileBaseImage : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> * string * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)
<Extension()>
Public Function WithDockerfileBaseImage(Of T As IResource) (builder As IResourceBuilder(Of T), Optional buildImage As String = Nothing, Optional runtimeImage As String = Nothing) As IResourceBuilder(Of T)
Type Parameters
- T
The type of resource.
Parameters
- builder
- IResourceBuilder<T>
The resource builder.
- buildImage
- String
The base image to use for the build stage. If null, uses the default build image.
- runtimeImage
- String
The base image to use for the runtime stage. If null, uses the default runtime image.
Returns
The IResourceBuilder<T>.
Remarks
This extension method allows customization of the base images used in generated Dockerfiles. For multi-stage Dockerfiles (e.g., Python with UV), you can specify separate build and runtime images.
var builder = DistributedApplication.CreateBuilder(args);
builder.AddPythonApp("myapp", "path/to/app", "main.py")
.WithDockerfileBaseImage(
buildImage: "ghcr.io/astral-sh/uv:python3.12-bookworm-slim",
runtimeImage: "python:3.12-slim-bookworm");
builder.Build().Run();