# ComposeFile Methods

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

Represents a Docker Compose file with properties and configurations for services, networks, volumes, secrets, configs, and custom extensions.

## AddConfig(Config)

- Name: `AddConfig(Config)`
- Returns: [ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/Resources/ComposeFile.cs#L150-L151)

Adds a new config entry to the Compose file.

```csharp
public sealed class ComposeFile
{
    public ComposeFile AddConfig(
        Config config)
    {
        // ...
    }
}
```

## Parameters

- `config` ([Config](/reference/api/csharp/aspire.hosting.docker/config.md))
  The config instance to add to the Compose file.

## Returns

[ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md) -- The updated [ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md) instance with the added config.

## AddNetwork(Network)

- Name: `AddNetwork(Network)`
- Returns: [ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/Resources/ComposeFile.cs#L117-L118)

Adds a new network to the Compose file.

```csharp
public sealed class ComposeFile
{
    public ComposeFile AddNetwork(
        Network network)
    {
        // ...
    }
}
```

## Parameters

- `network` ([Network](/reference/api/csharp/aspire.hosting.docker/network.md))
  The network instance to add to the Compose file.

## Returns

[ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md) -- The updated [ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md) instance with the added network.

## AddService(Service)

- Name: `AddService(Service)`
- Returns: [ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/Resources/ComposeFile.cs#L128-L129)

Adds a new service to the Compose file.

```csharp
public sealed class ComposeFile
{
    public ComposeFile AddService(
        Service service)
    {
        // ...
    }
}
```

## Parameters

- `service` ([Service](/reference/api/csharp/aspire.hosting.docker/service.md))
  The service instance to add to the Compose file.

## Returns

[ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md) -- The updated [ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md) instance containing the added service.

## AddVolume(Volume)

- Name: `AddVolume(Volume)`
- Returns: [ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/Resources/ComposeFile.cs#L139-L140)

Adds a new volume to the Compose file.

```csharp
public sealed class ComposeFile
{
    public ComposeFile AddVolume(
        Volume volume)
    {
        // ...
    }
}
```

## Parameters

- `volume` ([Volume](/reference/api/csharp/aspire.hosting.docker/volume.md))
  The volume instance to add to the Compose file.

## Returns

[ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md) -- The updated [ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md) instance with the added volume.

## ToYaml(string)

- Name: `ToYaml(string)`
- Returns: `string`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/Resources/ComposeFile.cs#L161-L171)

Converts the current instance of [ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md) to its YAML string representation.

```csharp
public sealed class ComposeFile
{
    public string ToYaml(
        string lineEndings = "\n")
    {
        // ...
    }
}
```

## Parameters

- `lineEndings` (`string`) `optional`
  Specifies the line endings to be used in the serialized YAML output. Defaults to "\n".

## Returns

`string` -- A string containing the YAML representation of the [ComposeFile](/reference/api/csharp/aspire.hosting.docker/composefile.md) instance.
