# WithVolume

- 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)

Adds a volume to a container resource.

## Remarks

Volumes persist data across container restarts. Named volumes are managed
by Docker/Podman and stored in a system-managed location.
Why this wrapper exists: The original `ContainerResourceBuilderExtensions.WithVolume`
has parameter order `(name?, target, isReadOnly)` where the optional `name` comes first.
This wrapper reorders parameters to `(target, name?, isReadOnly)` so the required `target`
parameter comes first, providing a better API for polyglot consumers.

## Definition

```go
func (ContainerResource) WithVolume(
    target string,
    options ...*WithVolumeOptions,
) ContainerResource
```

## Parameters

- `target` (`string`) -- The mount path inside the container.
- `options` (`...*WithVolumeOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*WithVolumeOptions` argument.

- `Name` (`*string`) -- The volume name. If null, an anonymous volume is created.
- `IsReadOnly` (`*bool`) -- Whether the volume is read-only.

## Returns

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

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

## Applies to

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