Skip to content

(aws-ecr-assets): TarballImageAsset does not use CDK_DOCKER environment variable #35336

@apmclean

Description

@apmclean

Describe the bug

The docker command executable is hard-coded in container arguments.

https://github.com/aws/aws-cdk/blob/bc333e267620fa2e3b7add39c565548e778cd01f/packages/aws-cdk-lib/
aws-ecr-assets/lib/tarball-asset.ts#L110

    const location = stack.synthesizer.addDockerImageAsset({
      sourceHash: stagedTarball.assetHash,
      executable: [
        'sh',
        '-c',
        `docker load -i ${relativePathInOutDir} | tail -n 1 | sed "${DOCKER_LOAD_OUTPUT_REGEX}"`,
      ],
      displayName: props.displayName ?? Names.stackRelativeConstructPath(this),
    });

When using an alternate runtime like Finch, and leveraging the CDK_DOCKER environment variable, the 'docker load' operation above fails silently. The 'tagging' operation attempted in a subsequent step fails with an empty string for the loaded container.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

No response

Expected Behavior

When using the CDK_DOCKER environment variable, Image asset from tarball successfully loaded, tagged, and pushed to the CDK Managed ECR Repository.

Current Behavior

import { TarballImageAsset } from 'aws-cdk-lib/aws-ecr-assets';
...
    const imageFromTarball = new TarballImageAsset(this, 'MyBuildImage', {
      tarballFile: path.join(__dirname, "..", "containerImage", "image.tar"),
    });
...
CDK_DOCKER=finch cdk deploy
time="2025-08-27T09:25:21-04:00" level=fatal msg="filters: parse error: [name==]: expected value or quoted: invalid argument: invalid argument"
stack: fail: finch tag  [account].dkr.ecr.us-east-1.amazonaws.com/cdk-hnb659fds-container-assets-[account]-us-east-1:d6be59455bcb6c49fe0db966ee21a2051e17bc3b1e8a6482fa8802151e2ab791 exited with error code 1: time="2025-08-27T09:25:21-04:00" level=fatal msg="filters: parse error: [name==]: expected value or quoted: invalid argument: invalid argument"

The tagging operation has successfully used the finch override, however the docker load operation has failed because it directly uses the docker command instead of what was specified within CDK_DOCKER.

Reproduction Steps

import { TarballImageAsset } from 'aws-cdk-lib/aws-ecr-assets';
...
    const imageFromTarball = new TarballImageAsset(this, 'MyBuildImage', {
      tarballFile: path.join(__dirname, "..", "containerImage", "image.tar"),
    });
...
CDK_DOCKER=finch cdk deploy

Possible Solution

TarballImageAsset needs to be updated to use the CDK_DOCKER environment variable.

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

[email protected]

AWS CDK CLI version

2.1026.0 (build ad1a7ce)

Node.js Version

v20.15.1

OS

15.6 (24G84)

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ecr-assetsRelated to AWS CDK Docker Image AssetsbugThis issue is a bug.effort/smallSmall work item – less than a day of effort

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions