# ContainerResource

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

A resource that represents a specified container.

## Definition

```go
type ContainerResource interface {
    IComputeResource
    Resource
    ResourceWithArgs
    ResourceWithEndpoints
    ResourceWithEnvironment
    ResourceWithWaitSupport
}
```

## Embeds

- [`IComputeResource`](/reference/api/go/aspire.hosting/icomputeresource.md)
- [`Resource`](/reference/api/go/aspire.hosting/resource.md)
- [`ResourceWithArgs`](/reference/api/go/aspire.hosting/resourcewithargs.md)
- [`ResourceWithEndpoints`](/reference/api/go/aspire.hosting/resourcewithendpoints.md)
- [`ResourceWithEnvironment`](/reference/api/go/aspire.hosting/resourcewithenvironment.md)
- [`ResourceWithWaitSupport`](/reference/api/go/aspire.hosting/resourcewithwaitsupport.md)

## Methods

- [PublishAsConnectionString](/reference/api/go/aspire.hosting/containerresource/publishasconnectionstring.md) -- `method` -- Changes the resource to be published as a connection string reference in the manifest.
  ```go
  PublishAsConnectionString() ContainerResource
  ```
- [PublishAsContainer](/reference/api/go/aspire.hosting/containerresource/publishascontainer.md) -- `method` -- Changes the resource to be published as a container in the manifest.
  ```go
  PublishAsContainer() ContainerResource
  ```
- [WithBindMount](/reference/api/go/aspire.hosting/containerresource/withbindmount.md) -- `method` -- Adds a bind mount to a container resource.
  ```go
  WithBindMount(source string, target string, options ...*WithBindMountOptions) ContainerResource
  ```
- [WithBuildArg](/reference/api/go/aspire.hosting/containerresource/withbuildarg.md) -- `method` -- Adds a build argument when the container is built from a Dockerfile.
  ```go
  WithBuildArg(name string, value any) ContainerResource
  ```
- [WithBuildSecret](/reference/api/go/aspire.hosting/containerresource/withbuildsecret.md) -- `method` -- Adds a secret build argument when the container is built from a Dockerfile.
  ```go
  WithBuildSecret(name string, value ParameterResource) ContainerResource
  ```
- [WithContainerCertificatePaths](/reference/api/go/aspire.hosting/containerresource/withcontainercertificatepaths.md) -- `method` -- Adds container certificate path overrides used for certificate trust at run time.
  ```go
  WithContainerCertificatePaths(options ...*WithContainerCertificatePathsOptions) ContainerResource
  ```
- [WithContainerFiles](/reference/api/go/aspire.hosting/containerresource/withcontainerfiles.md) -- `method` -- Creates or updates files and folders in a container by copying them from a source path on the host.
  ```go
  WithContainerFiles(destinationPath string, sourcePath string, options ...*ContainerFilesOptions) ContainerResource
  ```
- [WithContainerFilesCallback](/reference/api/go/aspire.hosting/containerresource/withcontainerfilescallback.md) -- `method` -- Creates or updates files and/or folders at the destination path in the container using entries produced by a callback.
  ```go
  WithContainerFilesCallback(destinationPath string, callback func(arg1 ContainerFileSystemCallbackContext, arg2 *CancellationToken) []ContainerFileSystemItem, options ...*ContainerFilesOptions) ContainerResource
  ```
- [WithContainerName](/reference/api/go/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.
  ```go
  WithContainerName(name string) ContainerResource
  ```
- [WithContainerNetworkAlias](/reference/api/go/aspire.hosting/containerresource/withcontainernetworkalias.md) -- `method` -- Adds a network alias to container resource.
  ```go
  WithContainerNetworkAlias(alias string) ContainerResource
  ```
- [WithContainerRuntimeArgs](/reference/api/go/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.
  ```go
  WithContainerRuntimeArgs(args []string) ContainerResource
  ```
- [WithDockerfile](/reference/api/go/aspire.hosting/containerresource/withdockerfile.md) -- `method` -- Causes Aspire to build the specified container image from a Dockerfile.
  ```go
  WithDockerfile(contextPath string, options ...*WithDockerfileOptions) ContainerResource
  ```
- [WithDockerfileBuilder](/reference/api/go/aspire.hosting/containerresource/withdockerfilebuilder.md) -- `method` -- Configures the resource to use a programmatically generated Dockerfile
  ```go
  WithDockerfileBuilder(contextPath string, callback func(arg DockerfileBuilderCallbackContext), options ...*WithDockerfileBuilderOptions) ContainerResource
  ```
- [WithDockerfileFactory](/reference/api/go/aspire.hosting/containerresource/withdockerfilefactory.md) -- `method` -- Builds the specified container image from a Dockerfile generated by an asynchronous factory function.
  ```go
  WithDockerfileFactory(contextPath string, dockerfileFactory func(arg DockerfileFactoryContext) string, options ...*WithDockerfileFactoryOptions) ContainerResource
  ```
- [WithEntrypoint](/reference/api/go/aspire.hosting/containerresource/withentrypoint.md) -- `method` -- Sets the Entrypoint for the container.
  ```go
  WithEntrypoint(entrypoint string) ContainerResource
  ```
- [WithImage](/reference/api/go/aspire.hosting/containerresource/withimage.md) -- `method` -- Allows overriding the image on a container.
  ```go
  WithImage(image string, options ...*WithImageOptions) ContainerResource
  ```
- [WithImagePullPolicy](/reference/api/go/aspire.hosting/containerresource/withimagepullpolicy.md) -- `method` -- Sets the pull policy for the container resource.
  ```go
  WithImagePullPolicy(pullPolicy ImagePullPolicy) ContainerResource
  ```
- [WithImageRegistry](/reference/api/go/aspire.hosting/containerresource/withimageregistry.md) -- `method` -- Allows overriding the image registry on a container.
  ```go
  WithImageRegistry(registry string) ContainerResource
  ```
- [WithImageSHA256](/reference/api/go/aspire.hosting/containerresource/withimagesha256.md) -- `method` -- Allows setting the image to a specific sha256 on a container.
  ```go
  WithImageSHA256(sha256 string) ContainerResource
  ```
- [WithImageTag](/reference/api/go/aspire.hosting/containerresource/withimagetag.md) -- `method` -- Allows overriding the image tag on a container.
  ```go
  WithImageTag(tag string) ContainerResource
  ```
- [WithLifetime](/reference/api/go/aspire.hosting/containerresource/withlifetime.md) -- `method` -- Sets the lifetime behavior of the container resource.
  ```go
  WithLifetime(lifetime ContainerLifetime) ContainerResource
  ```
- [WithVolume](/reference/api/go/aspire.hosting/containerresource/withvolume.md) -- `method` -- Adds a volume to a container resource.
  ```go
  WithVolume(target string, options ...*WithVolumeOptions) ContainerResource
  ```
