# ContainerResource.WithContainerName

- Module: [Aspire.Hosting](/reference/api/go/aspire.hosting.md)
- Defined on: [ContainerResource](/reference/api/go/aspire.hosting/containerresource.md)
- Version: `17.0.0`
- Kind: `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.

## Remarks

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

## Definition

```go
type ContainerResource interface {
    // ... omitted for brevity
    WithContainerName(name string) ContainerResource
}
```

## Signature

```go
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()`.

## Defined on

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