# AddDockerfileBuilder

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

Adds a container resource built from a programmatically generated Dockerfile

## Remarks

Use the callback's Dockerfile builder to define the image's stages and instructions.
The build context path is relative to the AppHost directory unless it is fully qualified.

## Definition

```go
func (DistributedApplicationBuilder) AddDockerfileBuilder(
    name string,
    contextPath string,
    callback func(arg DockerfileBuilderCallbackContext),
    options ...*AddDockerfileBuilderOptions,
) ContainerResource
```

## Parameters

- `name` (`string`) -- The name of the resource.
- `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` (`...*AddDockerfileBuilderOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*AddDockerfileBuilderOptions` 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()`.

## Applies to

- [`DistributedApplicationBuilder`](/reference/api/go/aspire.hosting/distributedapplicationbuilder.md)
