# ContainerResourceBuilderExtensions

- Kind: `class`
- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Version: `13.3.0`
- Namespace: `Aspire.Hosting`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs)

Provides extension methods for [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md) to add container resources to the application.

## Definition

```csharp
namespace Aspire.Hosting;

public static class ContainerResourceBuilderExtensions
{
    // ...
}
```

## Methods

- [AddContainer(IDistributedApplicationBuilder, string, string)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#addcontainer-idistributedapplicationbuilder-string-string) : `IResourceBuilder<ContainerResource>` `extension` `ats ignored` -- Adds a container resource to the application. Uses the "latest" tag.
- [AddContainer(IDistributedApplicationBuilder, string, string, string)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#addcontainer-idistributedapplicationbuilder-string-string-string) : `IResourceBuilder<ContainerResource>` `extension` `ats ignored` -- Adds a container resource to the application.
- [AddDockerfile(IDistributedApplicationBuilder, string, string, string?, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#adddockerfile-idistributedapplicationbuilder-string-string-string-string) : `IResourceBuilder<ContainerResource>` `extension` `ats export` -- Adds a Dockerfile to the application model that can be treated like a container resource.
- [AddDockerfileBuilder(IDistributedApplicationBuilder, string, string, Func<DockerfileBuilderCallbackContext, Task>, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#adddockerfilebuilder-idistributedapplicationbuilder-string-string-func-dockerfilebuildercallbackcontext-task-string) : `IResourceBuilder<ContainerResource>` `extension` `experimental` `ats export` -- Adds a Dockerfile to the application model that can be treated like a container resource, with the Dockerfile generated programmatically using the [DockerfileBuilder](/reference/api/csharp/aspire.hosting/dockerfilebuilder.md) API.
- [AddDockerfileBuilder(IDistributedApplicationBuilder, string, string, Action<DockerfileBuilderCallbackContext>, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#adddockerfilebuilder-idistributedapplicationbuilder-string-string-action-dockerfilebuildercallbackcontext-string) : `IResourceBuilder<ContainerResource>` `extension` `experimental` `ats ignored` -- Adds a Dockerfile to the application model that can be treated like a container resource, with the Dockerfile generated programmatically using the [DockerfileBuilder](/reference/api/csharp/aspire.hosting/dockerfilebuilder.md) API.
- [AddDockerfileFactory(IDistributedApplicationBuilder, string, string, Func<DockerfileFactoryContext, string>, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#adddockerfilefactory-idistributedapplicationbuilder-string-string-func-dockerfilefactorycontext-string-string) : `IResourceBuilder<ContainerResource>` `extension` `ats ignored` -- Adds a Dockerfile to the application model that can be treated like a container resource, with the Dockerfile content generated by a synchronous factory function.
- [AddDockerfileFactory(IDistributedApplicationBuilder, string, string, Func<DockerfileFactoryContext, Task<string>>, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#adddockerfilefactory-idistributedapplicationbuilder-string-string-func-dockerfilefactorycontext-task-string-string) : `IResourceBuilder<ContainerResource>` `extension` `ats ignored` -- Adds a Dockerfile to the application model that can be treated like a container resource, with the Dockerfile content generated by an asynchronous factory function.
- [PublishAsContainer(IResourceBuilder<T>)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#publishascontainer-iresourcebuilder-t) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Changes the resource to be published as a container in the manifest.
- [WithBindMount(IResourceBuilder<T>, string, string, bool)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withbindmount-iresourcebuilder-t-string-string-bool) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Adds a bind mount to a container resource.
- [WithBuildArg(IResourceBuilder<T>, string, object?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withbuildarg-iresourcebuilder-t-string-object) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats ignored` -- Adds a build argument when the container is build from a Dockerfile.
- [WithBuildArg(IResourceBuilder<T>, string, IResourceBuilder<ParameterResource>)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withbuildarg-iresourcebuilder-t-string-iresourcebuilder-parameterresource) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats ignored` -- Adds a build argument when the container is built from a Dockerfile.
- [WithBuildSecret(IResourceBuilder<T>, string, IResourceBuilder<ParameterResource>)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withbuildsecret-iresourcebuilder-t-string-iresourcebuilder-parameterresource) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Adds a secret build argument when the container is built from a Dockerfile.
- [WithContainerCertificatePaths(IResourceBuilder<TResource>, string?, List<string>, List<string>)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withcontainercertificatepaths-iresourcebuilder-tresource-string-list-string-list-string) : `IResourceBuilder<TResource>` `extension` `ats ignored` -- Adds a [ContainerCertificatePathsAnnotation](/reference/api/csharp/aspire.hosting/containercertificatepathsannotation.md) to the resource that allows overriding the default paths in the container used for certificate trust. Custom certificate trust is only supported at run time.
- [WithContainerFiles(IResourceBuilder<T>, string, IEnumerable<ContainerFileSystemItem>, int?, int?, UnixFileMode?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withcontainerfiles-iresourcebuilder-t-string-ienumerable-containerfilesystemitem-int-int-unixfilemode) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats ignored` -- Creates or updates files and/or folders at the destination path in the container.
- [WithContainerFiles(IResourceBuilder<T>, string, Func<ContainerFileSystemCallbackContext, CancellationToken, Task<IEnumerable<ContainerFileSystemItem>>>, int?, int?, UnixFileMode?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withcontainerfiles-iresourcebuilder-t-string-func-containerfilesystemcallbackcontext-cancellationtoken-task-ienumerable-containerfilesystemitem-int-int-unixfilemode) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats ignored` -- Creates or updates files and/or folders at the destination path in the container. Receives a callback that will be invoked when the container is started to allow the files to be created based on other resources in the application model.
- [WithContainerFiles(IResourceBuilder<T>, string, string, int?, int?, UnixFileMode?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withcontainerfiles-iresourcebuilder-t-string-string-int-int-unixfilemode) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats ignored` -- Creates or updates files and/or folders at the destination path in the container by copying them from a source path on the host. In run mode, this will copy the files from the host to the container at runtime, allowing for overriding ownership and permissions in the container. In publish mode, this will create a bind mount to the source path on the host.
- [WithContainerName(IResourceBuilder<T>, string)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withcontainername-iresourcebuilder-t-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Overrides the default container name for this resource. By default Aspire generates a unique container name based on the resource name and a random postfix (or a postfix based on a hash of the AppHost project path for persistent container resources). This method allows you to override that behavior with a custom name, but could lead to naming conflicts if the specified name is not unique.
- [WithContainerNetworkAlias(IResourceBuilder<T>, string)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withcontainernetworkalias-iresourcebuilder-t-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Adds a network alias to container resource.
- [WithContainerRuntimeArgs(IResourceBuilder<T>, string[])](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withcontainerruntimeargs-iresourcebuilder-t-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Adds a callback to be executed with a list of arguments to add to the container runtime run command when a container resource is started.
- [WithContainerRuntimeArgs(IResourceBuilder<T>, Action<ContainerRuntimeArgsCallbackContext>)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withcontainerruntimeargs-iresourcebuilder-t-action-containerruntimeargscallbackcontext) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats ignored` -- Adds a callback to be executed with a list of arguments to add to the container runtime run command when a container resource is started.
- [WithContainerRuntimeArgs(IResourceBuilder<T>, Func<ContainerRuntimeArgsCallbackContext, Task>)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withcontainerruntimeargs-iresourcebuilder-t-func-containerruntimeargscallbackcontext-task) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats ignored` -- Adds a callback to be executed with a list of arguments to add to the container runtime run command when a container resource is started.
- [WithDockerfile(IResourceBuilder<T>, string, string?, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withdockerfile-iresourcebuilder-t-string-string-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Causes Aspire to build the specified container image from a Dockerfile.
- [WithDockerfileBaseImage(IResourceBuilder<T>, string?, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withdockerfilebaseimage-iresourcebuilder-t-string-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `experimental` `ats export` -- Configures custom base images for generated Dockerfiles.
- [WithDockerfileBuilder(IResourceBuilder<T>, string, Func<DockerfileBuilderCallbackContext, Task>, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withdockerfilebuilder-iresourcebuilder-t-string-func-dockerfilebuildercallbackcontext-task-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `experimental` `ats export` -- Builds the specified container image from a Dockerfile generated by a callback using the [DockerfileBuilder](/reference/api/csharp/aspire.hosting/dockerfilebuilder.md) API.
- [WithDockerfileBuilder(IResourceBuilder<T>, string, Action<DockerfileBuilderCallbackContext>, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withdockerfilebuilder-iresourcebuilder-t-string-action-dockerfilebuildercallbackcontext-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `experimental` `ats ignored` -- Builds the specified container image from a Dockerfile generated by a synchronous callback using the [DockerfileBuilder](/reference/api/csharp/aspire.hosting/dockerfilebuilder.md) API.
- [WithDockerfileFactory(IResourceBuilder<T>, string, Func<DockerfileFactoryContext, string>, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withdockerfilefactory-iresourcebuilder-t-string-func-dockerfilefactorycontext-string-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats ignored` -- Builds the specified container image from a Dockerfile generated by a synchronous factory function.
- [WithDockerfileFactory(IResourceBuilder<T>, string, Func<DockerfileFactoryContext, Task<string>>, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withdockerfilefactory-iresourcebuilder-t-string-func-dockerfilefactorycontext-task-string-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats ignored` -- Builds the specified container image from a Dockerfile generated by an asynchronous factory function.
- [WithEndpointProxySupport(IResourceBuilder<T>, bool)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withendpointproxysupport-iresourcebuilder-t-bool) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Set whether a container resource can use proxied endpoints or whether they should be disabled for all endpoints belonging to the container. If set to `false`, endpoints belonging to the container resource will ignore the configured proxy settings and run proxy-less.
- [WithEntrypoint(IResourceBuilder<T>, string)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withentrypoint-iresourcebuilder-t-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Sets the Entrypoint for the container.
- [WithImage(IResourceBuilder<T>, string, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withimage-iresourcebuilder-t-string-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Allows overriding the image on a container.
- [WithImagePullPolicy(IResourceBuilder<T>, ImagePullPolicy)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withimagepullpolicy-iresourcebuilder-t-imagepullpolicy) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Sets the pull policy for the container resource.
- [WithImageRegistry(IResourceBuilder<T>, string?)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withimageregistry-iresourcebuilder-t-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Allows overriding the image registry on a container.
- [WithImageSHA256(IResourceBuilder<T>, string)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withimagesha256-iresourcebuilder-t-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Allows setting the image to a specific sha256 on a container.
- [WithImageTag(IResourceBuilder<T>, string)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withimagetag-iresourcebuilder-t-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Allows overriding the image tag on a container.
- [WithLifetime(IResourceBuilder<T>, ContainerLifetime)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withlifetime-iresourcebuilder-t-containerlifetime) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats export` -- Sets the lifetime behavior of the container resource.
- [WithVolume(IResourceBuilder<T>, string?, string, bool)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withvolume-iresourcebuilder-t-string-string-bool) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats ignored` -- Adds a volume to a container resource.
- [WithVolume(IResourceBuilder<T>, string)](/reference/api/csharp/aspire.hosting/containerresourcebuilderextensions/methods.md#withvolume-iresourcebuilder-t-string) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `extension` `ats ignored` -- Adds an anonymous volume to a container resource.
