# DockerComposeServiceExtensions Methods

- Package: [Aspire.Hosting.Docker](/reference/api/csharp/aspire.hosting.docker.md)
- Type: [DockerComposeServiceExtensions](/reference/api/csharp/aspire.hosting.docker/dockercomposeserviceextensions.md)
- Kind: `Methods`
- Members: `4`

Provides extension methods for customizing Docker Compose service resources.

## AsEnvironmentPlaceholder(IManifestExpressionProvider, DockerComposeServiceResource)

- Name: `AsEnvironmentPlaceholder(IManifestExpressionProvider, DockerComposeServiceResource)`
- Modifiers: `extension`
- Returns: `string`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/DockerComposeServiceExtensions.cs#L61-L70)

Creates a placeholder for an environment variable in the Docker Compose file.

```csharp
public static class DockerComposeServiceExtensions
{
    public static string AsEnvironmentPlaceholder(
        this IManifestExpressionProvider manifestExpressionProvider,
        DockerComposeServiceResource dockerComposeService)
    {
        // ...
    }
}
```

## Parameters

- `manifestExpressionProvider` (`IManifestExpressionProvider`)
  The manifest expression provider.
- `dockerComposeService` ([DockerComposeServiceResource](/reference/api/csharp/aspire.hosting.docker/dockercomposeserviceresource.md))
  The Docker Compose service resource to associate the environment variable with.

## Returns

`string` -- A string representing the environment variable placeholder in Docker Compose syntax (e.g., `${ENV_VAR}`).

## Remarks

This overload is not available in polyglot app hosts because `ApplicationModel.IManifestExpressionProvider` is not ATS-compatible.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AsEnvironmentPlaceholder(IResourceBuilder<ParameterResource>, DockerComposeServiceResource)

- Name: `AsEnvironmentPlaceholder(IResourceBuilder<ParameterResource>, DockerComposeServiceResource)`
- Modifiers: `extension`
- Returns: `string`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/DockerComposeServiceExtensions.cs#L85)

Creates a Docker Compose environment variable placeholder for the specified `ApplicationModel.ParameterResource`.

```csharp
public static class DockerComposeServiceExtensions
{
    public static string AsEnvironmentPlaceholder(
        this IResourceBuilder<ParameterResource> builder,
        DockerComposeServiceResource dockerComposeService)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ParameterResource>`)
  The resource builder for the parameter resource.
- `dockerComposeService` ([DockerComposeServiceResource](/reference/api/csharp/aspire.hosting.docker/dockercomposeserviceresource.md))
  The Docker Compose service resource to associate the environment variable with.

## Returns

`string` -- A string representing the environment variable placeholder in Docker Compose syntax (e.g., `${ENV_VAR}`).

## Remarks

Use this overload with parameter builders returned by methods such as `ParameterResourceBuilderExtensions.AddParameter`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AsEnvironmentPlaceholder(ParameterResource, DockerComposeServiceResource)

- Name: `AsEnvironmentPlaceholder(ParameterResource, DockerComposeServiceResource)`
- Modifiers: `extension`
- Returns: `string`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/DockerComposeServiceExtensions.cs#L101-L110)

Creates a Docker Compose environment variable placeholder for this `ApplicationModel.ParameterResource`.

```csharp
public static class DockerComposeServiceExtensions
{
    public static string AsEnvironmentPlaceholder(
        this ParameterResource parameter,
        DockerComposeServiceResource dockerComposeService)
    {
        // ...
    }
}
```

## Parameters

- `parameter` (`ParameterResource`)
  The parameter resource for which to create the environment variable placeholder.
- `dockerComposeService` ([DockerComposeServiceResource](/reference/api/csharp/aspire.hosting.docker/dockercomposeserviceresource.md))
  The Docker Compose service resource to associate the environment variable with.

## Returns

`string` -- A string representing the environment variable placeholder in Docker Compose syntax (e.g., `${ENV_VAR}`).

## Remarks

This overload is not available in polyglot app hosts. Use the builder or manifest-expression overload instead.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## PublishAsDockerComposeService(IResourceBuilder<T>, Action<DockerComposeServiceResource, Service>)

- Name: `PublishAsDockerComposeService(IResourceBuilder<T>, Action<DockerComposeServiceResource, Service>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<T>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/DockerComposeServiceExtensions.cs#L38-L48)

Publishes the specified resource as a Docker Compose service.

```csharp
public static class DockerComposeServiceExtensions
{
    public static IResourceBuilder<T> PublishAsDockerComposeService<T>(
        this IResourceBuilder<T> builder,
        Action<DockerComposeServiceResource, Service> configure)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<T>`)
  The resource builder.
- `configure` (`Action<DockerComposeServiceResource, Service>`)
  The configuration action for the Docker Compose service.

## Returns

`IResourceBuilder<T>` -- The updated resource builder.

## Remarks

This method checks if the application is in publish mode. If it is, it adds a customization annotation that will be applied by the DockerComposeInfrastructure when generating the Docker Compose service.

```csharp
builder.AddContainer("redis", "redis:alpine").PublishAsDockerComposeService((resource, service) =>
{
    service.Name = "redis";
});
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
