# DockerImageSource

Properties for how to produce a Docker image from a source.

Used as argument in: [AssetManifestBuilder.addDockerImageAsset](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.AssetManifestBuilder.html#adddockerimageasset)

- Source: [`lib/assets/docker-image-asset.ts`](https://github.com/aws/aws-cdk-cli/blob/HEAD/packages/@aws-cdk/cloud-assembly-schema/lib/assets/docker-image-asset.ts)
- Type last changed: v2.245.0 · 27 Mar 2026

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { cloud_assembly_schema } from 'aws-cdk-lib';
const dockerImageSource: cloud_assembly_schema.DockerImageSource = {
  cacheDisabled: false,
  cacheFrom: [{
    type: 'type',

    // the properties below are optional
    params: {
      paramsKey: 'params',
    },
  }],
  cacheTo: {
    type: 'type',

    // the properties below are optional
    params: {
      paramsKey: 'params',
    },
  },
  directory: 'directory',
  dockerBuildArgs: {
    dockerBuildArgsKey: 'dockerBuildArgs',
  },
  dockerBuildContexts: {
    dockerBuildContextsKey: 'dockerBuildContexts',
  },
  dockerBuildSecrets: {
    dockerBuildSecretsKey: 'dockerBuildSecrets',
  },
  dockerBuildSsh: 'dockerBuildSsh',
  dockerBuildTarget: 'dockerBuildTarget',
  dockerFile: 'dockerFile',
  dockerOutputs: ['dockerOutputs'],
  executable: ['executable'],
  networkMode: 'networkMode',
  platform: 'platform',
};
```

Python:

```python
from aws_cdk.cloud_assembly_schema import DockerImageSource, DockerCacheOption, DockerCacheOption
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import cloud_assembly_schema

docker_image_source = DockerImageSource(
    cache_disabled=False,
    cache_from=[DockerCacheOption(
        type="type",

        # the properties below are optional
        params={
            "params_key": "params"
        }
    )],
    cache_to=DockerCacheOption(
        type="type",

        # the properties below are optional
        params={
            "params_key": "params"
        }
    ),
    directory="directory",
    docker_build_args={
        "docker_build_args_key": "dockerBuildArgs"
    },
    docker_build_contexts={
        "docker_build_contexts_key": "dockerBuildContexts"
    },
    docker_build_secrets={
        "docker_build_secrets_key": "dockerBuildSecrets"
    },
    docker_build_ssh="dockerBuildSsh",
    docker_build_target="dockerBuildTarget",
    docker_file="dockerFile",
    docker_outputs=["dockerOutputs"],
    executable=["executable"],
    network_mode="networkMode",
    platform="platform"
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.cloud_assembly_schema.*;

DockerImageSource dockerImageSource = DockerImageSource.builder()
        .cacheDisabled(false)
        .cacheFrom(List.of(DockerCacheOption.builder()
                .type("type")

                // the properties below are optional
                .params(Map.of(
                        "paramsKey", "params"))
                .build()))
        .cacheTo(DockerCacheOption.builder()
                .type("type")

                // the properties below are optional
                .params(Map.of(
                        "paramsKey", "params"))
                .build())
        .directory("directory")
        .dockerBuildArgs(Map.of(
                "dockerBuildArgsKey", "dockerBuildArgs"))
        .dockerBuildContexts(Map.of(
                "dockerBuildContextsKey", "dockerBuildContexts"))
        .dockerBuildSecrets(Map.of(
                "dockerBuildSecretsKey", "dockerBuildSecrets"))
        .dockerBuildSsh("dockerBuildSsh")
        .dockerBuildTarget("dockerBuildTarget")
        .dockerFile("dockerFile")
        .dockerOutputs(List.of("dockerOutputs"))
        .executable(List.of("executable"))
        .networkMode("networkMode")
        .platform("platform")
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.Cloud_assembly_schema;

var dockerImageSource = new DockerImageSource {
    CacheDisabled = false,
    CacheFrom = new [] { new DockerCacheOption {
        Type = "type",

        // the properties below are optional
        Params = new Dictionary<string, string> {
            { "paramsKey", "params" }
        }
    } },
    CacheTo = new DockerCacheOption {
        Type = "type",

        // the properties below are optional
        Params = new Dictionary<string, string> {
            { "paramsKey", "params" }
        }
    },
    Directory = "directory",
    DockerBuildArgs = new Dictionary<string, string> {
        { "dockerBuildArgsKey", "dockerBuildArgs" }
    },
    DockerBuildContexts = new Dictionary<string, string> {
        { "dockerBuildContextsKey", "dockerBuildContexts" }
    },
    DockerBuildSecrets = new Dictionary<string, string> {
        { "dockerBuildSecretsKey", "dockerBuildSecrets" }
    },
    DockerBuildSsh = "dockerBuildSsh",
    DockerBuildTarget = "dockerBuildTarget",
    DockerFile = "dockerFile",
    DockerOutputs = new [] { "dockerOutputs" },
    Executable = new [] { "executable" },
    NetworkMode = "networkMode",
    Platform = "platform"
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

dockerImageSource := &DockerImageSource{
	CacheDisabled: jsii.Boolean(false),
	CacheFrom: []DockerCacheOption{
		&DockerCacheOption{
			Type: jsii.String("type"),

			// the properties below are optional
			Params: map[string]*string{
				"paramsKey": jsii.String("params"),
			},
		},
	},
	CacheTo: &DockerCacheOption{
		Type: jsii.String("type"),

		// the properties below are optional
		Params: map[string]*string{
			"paramsKey": jsii.String("params"),
		},
	},
	Directory: jsii.String("directory"),
	DockerBuildArgs: map[string]*string{
		"dockerBuildArgsKey": jsii.String("dockerBuildArgs"),
	},
	DockerBuildContexts: map[string]*string{
		"dockerBuildContextsKey": jsii.String("dockerBuildContexts"),
	},
	DockerBuildSecrets: map[string]*string{
		"dockerBuildSecretsKey": jsii.String("dockerBuildSecrets"),
	},
	DockerBuildSsh: jsii.String("dockerBuildSsh"),
	DockerBuildTarget: jsii.String("dockerBuildTarget"),
	DockerFile: jsii.String("dockerFile"),
	DockerOutputs: []*string{
		jsii.String("dockerOutputs"),
	},
	Executable: []*string{
		jsii.String("executable"),
	},
	NetworkMode: jsii.String("networkMode"),
	Platform: jsii.String("platform"),
}
```

## Properties

- `cacheDisabled`: boolean — Disable the cache and pass `--no-cache` to the `docker build` command.

  **Default:** cache is used

- `cacheFrom`: [DockerCacheOption](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.cloud_assembly_schema.DockerCacheOption.html)[] — Cache from options to pass to the `docker build` command.

  **Default:** no cache from options are passed to the build command

- `cacheTo`: [DockerCacheOption](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.cloud_assembly_schema.DockerCacheOption.html) — Cache to options to pass to the `docker build` command.

  **Default:** no cache to options are passed to the build command

- `directory`: string — The directory containing the Docker image build instructions.

  **Default:** Exactly one of `directory` and `executable` is required

  This path is relative to the asset manifest location.

- `dockerBuildArgs`: { [key: string]: string } — Additional build arguments.

  **Default:** No additional build arguments

  Only allowed when `directory` is set.

- `dockerBuildContexts`: { [key: string]: string } — Additional build contexts.

  **Default:** No additional build contexts

  Only allowed when `directory` is set.

- `dockerBuildSecrets`: { [key: string]: string } — Additional build secrets.

  **Default:** No additional build secrets

  Only allowed when `directory` is set.

- `dockerBuildSsh`: string — SSH agent socket or keys.

  **Default:** No ssh flag is set

  Requires building with docker buildkit.

- `dockerBuildTarget`: string — Target build stage in a Dockerfile with multiple build stages.

  **Default:** The last stage in the Dockerfile

  Only allowed when `directory` is set.

- `dockerFile`: string = "Dockerfile" — The name of the file with build instructions.

  Only allowed when `directory` is set.

- `dockerOutputs`: string[] — Outputs.

  **Default:** no outputs are passed to the build command (default outputs are used)

- `executable`: string[] — A command-line executable that returns the name of a local Docker image on stdout after being run.

  **Default:** Exactly one of `directory` and `executable` is required

- `networkMode`: string — Networking mode for the RUN commands during build. _Requires Docker Engine API v1.25+_.

  **Default:** no networking mode specified

  Specify this property to build images on a specific networking mode.

- `platform`: string — Platform to build for. _Requires Docker Buildx_.

  **Default:** current machine platform

  Specify this property to build images on a specific platform/architecture.
