# IContainerRuntime Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [IContainerRuntime](/reference/api/csharp/aspire.hosting/icontainerruntime.md)
- Kind: `Methods`
- Members: `9`

Represents a container runtime (e.g., Docker, Podman) that can be used to build, tag, push, and manage container images.

## BuildImageAsync(string, string, ContainerImageBuildOptions?, Dictionary<string, string?>, Dictionary<string, BuildImageSecretValue>, string?, CancellationToken)

- Name: `BuildImageAsync(string, string, ContainerImageBuildOptions?, Dictionary<string, string?>, Dictionary<string, BuildImageSecretValue>, string?, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task`

Builds a container image from a Dockerfile.

```csharp
public interface IContainerRuntime
{
    public abstract Task BuildImageAsync(
        string contextPath,
        string dockerfilePath,
        ContainerImageBuildOptions? options,
        Dictionary<string, string?> buildArguments,
        Dictionary<string, BuildImageSecretValue> buildSecrets,
        string? stage,
        CancellationToken cancellationToken)
    {
        // ...
    }
}
```

## Parameters

- `contextPath` (`string`)
  The build context path.
- `dockerfilePath` (`string`)
  The path to the Dockerfile.
- `options` ([ContainerImageBuildOptions?](/reference/api/csharp/aspire.hosting/containerimagebuildoptions.md))
  Build options including image name and tag.
- `buildArguments` (`Dictionary<string, string?>`)
  Build arguments to pass to the build process.
- `buildSecrets` (`Dictionary<string, BuildImageSecretValue>`)
  Build secrets to pass to the build process.
- `stage` (`string?`)
  The target build stage.
- `cancellationToken` (`CancellationToken`)
  A token to cancel the operation.

## CheckIfRunningAsync(CancellationToken)

- Name: `CheckIfRunningAsync(CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task<bool>`

Checks if the container runtime is running and available.

```csharp
public interface IContainerRuntime
{
    public abstract Task<bool> CheckIfRunningAsync(
        CancellationToken cancellationToken)
    {
        // ...
    }
}
```

## Parameters

- `cancellationToken` (`CancellationToken`)
  A token to cancel the operation.

## Returns

`Task<bool>` -- True if the container runtime is running; otherwise, false.

## ComposeDownAsync(ComposeOperationContext, CancellationToken)

- Name: `ComposeDownAsync(ComposeOperationContext, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task`

Stops and removes compose services.

```csharp
public interface IContainerRuntime
{
    public abstract Task ComposeDownAsync(
        ComposeOperationContext context,
        CancellationToken cancellationToken)
    {
        // ...
    }
}
```

## Parameters

- `context` ([ComposeOperationContext](/reference/api/csharp/aspire.hosting/composeoperationcontext.md))
  The compose operation parameters.
- `cancellationToken` (`CancellationToken`)
  A token to cancel the operation.

## Exceptions

- [DistributedApplicationException](/reference/api/csharp/aspire.hosting/distributedapplicationexception.md) -- Thrown when the compose down command fails.

## ComposeListServicesAsync(ComposeOperationContext, CancellationToken)

- Name: `ComposeListServicesAsync(ComposeOperationContext, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task<IReadOnlyList<ComposeServiceInfo>>`

Lists the running services in a compose environment with their port mappings.

```csharp
public interface IContainerRuntime
{
    public abstract Task<IReadOnlyList<ComposeServiceInfo>?> ComposeListServicesAsync(
        ComposeOperationContext context,
        CancellationToken cancellationToken)
    {
        // ...
    }
}
```

## Parameters

- `context` ([ComposeOperationContext](/reference/api/csharp/aspire.hosting/composeoperationcontext.md))
  The compose operation parameters.
- `cancellationToken` (`CancellationToken`)
  A token to cancel the operation.

## Returns

`Task<IReadOnlyList<ComposeServiceInfo>>` -- A list of running services, or `null` if the query could not be completed.

## ComposeUpAsync(ComposeOperationContext, CancellationToken)

- Name: `ComposeUpAsync(ComposeOperationContext, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task`

Starts compose services in detached mode.

```csharp
public interface IContainerRuntime
{
    public abstract Task ComposeUpAsync(
        ComposeOperationContext context,
        CancellationToken cancellationToken)
    {
        // ...
    }
}
```

## Parameters

- `context` ([ComposeOperationContext](/reference/api/csharp/aspire.hosting/composeoperationcontext.md))
  The compose operation parameters.
- `cancellationToken` (`CancellationToken`)
  A token to cancel the operation.

## Exceptions

- [DistributedApplicationException](/reference/api/csharp/aspire.hosting/distributedapplicationexception.md) -- Thrown when the compose up command fails.

## LoginToRegistryAsync(string, string, string, CancellationToken)

- Name: `LoginToRegistryAsync(string, string, string, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task`

Logs in to a container registry.

```csharp
public interface IContainerRuntime
{
    public abstract Task LoginToRegistryAsync(
        string registryServer,
        string username,
        string password,
        CancellationToken cancellationToken)
    {
        // ...
    }
}
```

## Parameters

- `registryServer` (`string`)
  The registry server URL.
- `username` (`string`)
  The username for authentication.
- `password` (`string`)
  The password for authentication.
- `cancellationToken` (`CancellationToken`)
  A token to cancel the operation.

## PushImageAsync(IResource, CancellationToken)

- Name: `PushImageAsync(IResource, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task`

Pushes a container image to a registry.

```csharp
public interface IContainerRuntime
{
    public abstract Task PushImageAsync(
        IResource resource,
        CancellationToken cancellationToken)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource containing push configuration.
- `cancellationToken` (`CancellationToken`)
  A token to cancel the operation.

## RemoveImageAsync(string, CancellationToken)

- Name: `RemoveImageAsync(string, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task`

Removes a container image.

```csharp
public interface IContainerRuntime
{
    public abstract Task RemoveImageAsync(
        string imageName,
        CancellationToken cancellationToken)
    {
        // ...
    }
}
```

## Parameters

- `imageName` (`string`)
  The name of the image to remove.
- `cancellationToken` (`CancellationToken`)
  A token to cancel the operation.

## TagImageAsync(string, string, CancellationToken)

- Name: `TagImageAsync(string, string, CancellationToken)`
- Modifiers: `abstract`
- Returns: `Task`

Tags a container image with a new name.

```csharp
public interface IContainerRuntime
{
    public abstract Task TagImageAsync(
        string localImageName,
        string targetImageName,
        CancellationToken cancellationToken)
    {
        // ...
    }
}
```

## Parameters

- `localImageName` (`string`)
  The current name of the image.
- `targetImageName` (`string`)
  The new name to assign to the image.
- `cancellationToken` (`CancellationToken`)
  A token to cancel the operation.
