# ContainerResource.WithDockerfileBuilder

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

Configures the resource to use a programmatically generated Dockerfile

## Remarks

Calling this method multiple times composes callbacks, which are invoked in registration order
to build the final Dockerfile.
The build context path is relative to the AppHost directory unless it is fully qualified.

## Definition

```go
type ContainerResource interface {
    // ... omitted for brevity
    WithDockerfileBuilder(
        contextPath string,
        callback func(arg DockerfileBuilderCallbackContext),
        options ...*WithDockerfileBuilderOptions,
    ) ContainerResource
}
```

## Signature

```go
WithDockerfileBuilder(
    contextPath string,
    callback func(arg DockerfileBuilderCallbackContext),
    options ...*WithDockerfileBuilderOptions,
) ContainerResource
```

## Parameters

- `contextPath` (`string`) -- Path to be used as the context for the container image build.
- `callback` (`func(arg DockerfileBuilderCallbackContext)`) -- A callback that uses the `DockerfileBuilder` API to construct the Dockerfile.
- `options` (`...*WithDockerfileBuilderOptions`) -- optional settings, see [Options](#options)

## Options

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

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

## Defined on

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