# WithDockerfile

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

Causes Aspire to build the specified container image from a Dockerfile.

## Definition

```go
func (ContainerResource) WithDockerfile(
    contextPath string,
    options ...*WithDockerfileOptions,
) ContainerResource
```

## Parameters

- `contextPath` (`string`) -- Path to be used as the context for the container image build.
- `options` (`...*WithDockerfileOptions`) -- optional settings, see [Options](#options)

## Options

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

- `DockerfilePath` (`*string`) -- Path to the Dockerfile relative to the `contextPath`. Defaults to "Dockerfile" if not specified.
- `Stage` (`*string`) -- The stage representing the image to be published in a multi-stage Dockerfile.

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