# ContainerResource

- Module: [Aspire.Hosting](/reference/api/typescript/aspire.hosting.md)
- Version: `13.4.0`
- Kind: `handle`
- Source: [GitHub](https://github.com/microsoft/aspire)

A resource that represents a specified container.

## Definition

```typescript
interface ContainerResource
  extends IComputeResource,
    IResource,
    IResourceWithArgs,
    IResourceWithEndpoints,
    IResourceWithEnvironment,
    IResourceWithProbes,
    IResourceWithWaitSupport {
  publishAsConnectionString(): ContainerResource;
  publishAsContainer(): ContainerResource;
  withBindMount(
      source: string,
      target: string,
      isReadOnly?: boolean): ContainerResource;
  withBuildArg(
      name: string,
      value: ParameterResource): ContainerResource;
  withBuildSecret(
      name: string,
      value: ParameterResource): ContainerResource;
  withContainerCertificatePaths(
      customCertificatesDestination?: string,
      defaultCertificateBundlePaths?: string[],
      defaultCertificateDirectoryPaths?: string[]): ContainerResource;
  withContainerName(name: string): ContainerResource;
  withContainerNetworkAlias(alias: string): ContainerResource;
  withContainerRuntimeArgs(args: string[]): ContainerResource;
  withDockerfile(
      contextPath: string,
      dockerfilePath?: string,
      stage?: string): ContainerResource;
  withDockerfileBuilder(contextPath: string, callback: (arg: DockerfileBuilderCallbackContext) => Promise<void>, stage?: string): ContainerResource;
  withDockerfileFactory(contextPath: string, dockerfileFactory: (arg: DockerfileFactoryContext) => Promise<string>, stage?: string): ContainerResource;
  withEntrypoint(entrypoint: string): ContainerResource;
  withImage(
      image: string,
      tag?: string): ContainerResource;
  withImagePullPolicy(pullPolicy: ImagePullPolicy): ContainerResource;
  withImageRegistry(registry: string): ContainerResource;
  withImageSHA256(sha256: string): ContainerResource;
  withImageTag(tag: string): ContainerResource;
  withLifetime(lifetime: ContainerLifetime): ContainerResource;
  withVolume(
      target: string,
      name?: string,
      isReadOnly?: boolean): ContainerResource;
}
```

## Methods

- [publishAsConnectionString](/reference/api/typescript/aspire.hosting/containerresource/publishasconnectionstring.md) -- `method` -- Changes the resource to be published as a connection string reference in the manifest.
    ```typescript
  publishAsConnectionString(): ContainerResource
  ```
- [publishAsContainer](/reference/api/typescript/aspire.hosting/containerresource/publishascontainer.md) -- `method` -- Changes the resource to be published as a container in the manifest.
    ```typescript
  publishAsContainer(): ContainerResource
  ```
- [withBindMount](/reference/api/typescript/aspire.hosting/containerresource/withbindmount.md) -- `method` -- Adds a bind mount to a container resource.
    ```typescript
  withBindMount(source: string, target: string, isReadOnly?: boolean): ContainerResource
  ```
- [withBuildArg](/reference/api/typescript/aspire.hosting/containerresource/withbuildarg.md) -- `method` -- Adds a build argument when the container is built from a Dockerfile.
    ```typescript
  withBuildArg(name: string, value: ParameterResource): ContainerResource
  ```
- [withBuildSecret](/reference/api/typescript/aspire.hosting/containerresource/withbuildsecret.md) -- `method` -- Adds a secret build argument when the container is built from a Dockerfile.
    ```typescript
  withBuildSecret(name: string, value: ParameterResource): ContainerResource
  ```
- [withContainerCertificatePaths](/reference/api/typescript/aspire.hosting/containerresource/withcontainercertificatepaths.md) -- `method` -- Adds container certificate path overrides used for certificate trust at run time.
    ```typescript
  withContainerCertificatePaths(customCertificatesDestination?: string, defaultCertificateBundlePaths?: string[], defaultCertificateDirectoryPaths?: string[]): ContainerResource
  ```
- [withContainerName](/reference/api/typescript/aspire.hosting/containerresource/withcontainername.md) -- `method` -- 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.
    ```typescript
  withContainerName(name: string): ContainerResource
  ```
- [withContainerNetworkAlias](/reference/api/typescript/aspire.hosting/containerresource/withcontainernetworkalias.md) -- `method` -- Adds a network alias to container resource.
    ```typescript
  withContainerNetworkAlias(alias: string): ContainerResource
  ```
- [withContainerRuntimeArgs](/reference/api/typescript/aspire.hosting/containerresource/withcontainerruntimeargs.md) -- `method` -- 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.
    ```typescript
  withContainerRuntimeArgs(args: string[]): ContainerResource
  ```
- [withDockerfile](/reference/api/typescript/aspire.hosting/containerresource/withdockerfile.md) -- `method` -- Causes Aspire to build the specified container image from a Dockerfile.
    ```typescript
  withDockerfile(contextPath: string, dockerfilePath?: string, stage?: string): ContainerResource
  ```
- [withDockerfileBuilder](/reference/api/typescript/aspire.hosting/containerresource/withdockerfilebuilder.md) -- `method` -- Configures the resource to use a programmatically generated Dockerfile
    ```typescript
  withDockerfileBuilder(contextPath: string, callback: (arg: DockerfileBuilderCallbackContext) => Promise<void>, stage?: string): ContainerResource
  ```
- [withDockerfileFactory](/reference/api/typescript/aspire.hosting/containerresource/withdockerfilefactory.md) -- `method` -- Builds the specified container image from a Dockerfile generated by an asynchronous factory function.
    ```typescript
  withDockerfileFactory(contextPath: string, dockerfileFactory: (arg: DockerfileFactoryContext) => Promise<string>, stage?: string): ContainerResource
  ```
- [withEntrypoint](/reference/api/typescript/aspire.hosting/containerresource/withentrypoint.md) -- `method` -- Sets the Entrypoint for the container.
    ```typescript
  withEntrypoint(entrypoint: string): ContainerResource
  ```
- [withImage](/reference/api/typescript/aspire.hosting/containerresource/withimage.md) -- `method` -- Allows overriding the image on a container.
    ```typescript
  withImage(image: string, tag?: string): ContainerResource
  ```
- [withImagePullPolicy](/reference/api/typescript/aspire.hosting/containerresource/withimagepullpolicy.md) -- `method` -- Sets the pull policy for the container resource.
    ```typescript
  withImagePullPolicy(pullPolicy: ImagePullPolicy): ContainerResource
  ```
- [withImageRegistry](/reference/api/typescript/aspire.hosting/containerresource/withimageregistry.md) -- `method` -- Allows overriding the image registry on a container.
    ```typescript
  withImageRegistry(registry: string): ContainerResource
  ```
- [withImageSHA256](/reference/api/typescript/aspire.hosting/containerresource/withimagesha256.md) -- `method` -- Allows setting the image to a specific sha256 on a container.
    ```typescript
  withImageSHA256(sha256: string): ContainerResource
  ```
- [withImageTag](/reference/api/typescript/aspire.hosting/containerresource/withimagetag.md) -- `method` -- Allows overriding the image tag on a container.
    ```typescript
  withImageTag(tag: string): ContainerResource
  ```
- [withLifetime](/reference/api/typescript/aspire.hosting/containerresource/withlifetime.md) -- `method` -- Sets the lifetime behavior of the container resource.
    ```typescript
  withLifetime(lifetime: ContainerLifetime): ContainerResource
  ```
- [withVolume](/reference/api/typescript/aspire.hosting/containerresource/withvolume.md) -- `method` -- Adds a volume to a container resource.
    ```typescript
  withVolume(target: string, name?: string, isReadOnly?: boolean): ContainerResource
  ```
