# WithContainerName

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

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.

## Remarks

Combining this with `Persistent` will allow Aspire to re-use an existing container that was not
created by an Aspire AppHost.

## Definition

```go
func (ContainerResource) WithContainerName(name string) ContainerResource
```

## Parameters

- `name` (`string`) -- The desired container name. Must be a valid container name or your runtime will report an error.

## Returns

[`ContainerResource`](/reference/api/go/aspire.hosting/containerresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- [`ContainerResource`](/reference/api/go/aspire.hosting/containerresource.md)
