From 82b6d353b1577996c3995e54827fa452604e5581 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 17:09:35 +0000 Subject: [PATCH 1/3] Initial plan From 23cc965af4457d6ed58a7f591afde35c377c9fc4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 17:14:11 +0000 Subject: [PATCH 2/3] Add clear explanation of AddDockerfile vs WithDockerfile differences Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com> --- docs/app-host/withdockerfile.md | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/app-host/withdockerfile.md b/docs/app-host/withdockerfile.md index 6f67a0f7a5..621aacee30 100644 --- a/docs/app-host/withdockerfile.md +++ b/docs/app-host/withdockerfile.md @@ -8,6 +8,30 @@ ms.date: 07/23/2024 With .NET Aspire it's possible to specify a _Dockerfile_ to build when the [app host](../fundamentals/app-host-overview.md) is started using either the or extension methods. +These two methods serve different purposes: + +- ****: Creates a new container resource from an existing Dockerfile. Use this when you want to add a custom containerized service to your app model. +- ****: Customizes an existing container resource (like a database or cache) to use a different Dockerfile. Use this when you want to modify the default container image for a .NET Aspire component. + +Both methods expect an existing Dockerfile in the specified context path—neither method creates a Dockerfile for you. + +## When to use AddDockerfile vs WithDockerfile + +Choose the appropriate method based on your scenario: + +**Use when:** + +- You want to add a custom containerized service to your app model +- You have an existing Dockerfile for a custom application or service +- You need to create a new container resource that isn't provided by .NET Aspire components + +**Use when:** + +- You want to customize an existing .NET Aspire component (like PostgreSQL, Redis, etc.) +- You need to replace the default container image with a custom one +- You want to maintain the strongly typed resource builder and its extension methods +- You have specific requirements that the default container image doesn't meet + ## Add a Dockerfile to the app model In the following example the extension method is used to specify a container by referencing the context path for the container build. @@ -39,14 +63,16 @@ var container = builder.ExecutionContext.IsRunMode When using the return value is an `IResourceBuilder`. .NET Aspire includes many custom resource types that are derived from . -Using the extension method it's possible to continue using these strongly typed resource types and customize the underlying container that is used. +Using the extension method it's possible to take an existing .NET Aspire component (like PostgreSQL, Redis, or SQL Server) and replace its default container image with a custom one built from your own Dockerfile. This allows you to continue using the strongly typed resource types and their specific extension methods while customizing the underlying container. ```csharp var builder = DistributedApplication.CreateBuilder(args); +// This replaces the default PostgreSQL container image with a custom one +// built from your Dockerfile, while keeping PostgreSQL-specific functionality var pgsql = builder.AddPostgres("pgsql") .WithDockerfile("path/to/context") - .WithPgAdmin(); + .WithPgAdmin(); // Still works because it's still a PostgreSQL resource ``` ## Pass build arguments From 02ef1bc0e4edb4ee52dc9882e8298b3df12b8781 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 16 Jul 2025 18:34:36 +0000 Subject: [PATCH 3/3] Fix bullet list punctuation in withdockerfile.md Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com> --- docs/app-host/withdockerfile.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/app-host/withdockerfile.md b/docs/app-host/withdockerfile.md index 621aacee30..5339ad33fd 100644 --- a/docs/app-host/withdockerfile.md +++ b/docs/app-host/withdockerfile.md @@ -21,16 +21,16 @@ Choose the appropriate method based on your scenario: **Use when:** -- You want to add a custom containerized service to your app model -- You have an existing Dockerfile for a custom application or service -- You need to create a new container resource that isn't provided by .NET Aspire components +- You want to add a custom containerized service to your app model. +- You have an existing Dockerfile for a custom application or service. +- You need to create a new container resource that isn't provided by .NET Aspire components. **Use when:** -- You want to customize an existing .NET Aspire component (like PostgreSQL, Redis, etc.) -- You need to replace the default container image with a custom one -- You want to maintain the strongly typed resource builder and its extension methods -- You have specific requirements that the default container image doesn't meet +- You want to customize an existing .NET Aspire component (like PostgreSQL, Redis, etc.). +- You need to replace the default container image with a custom one. +- You want to maintain the strongly typed resource builder and its extension methods. +- You have specific requirements that the default container image doesn't meet. ## Add a Dockerfile to the app model