aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

cdk synth: spawnSync docker ENOENT because cdk is not looking at the right directory

Open damshenas opened this issue 2 years ago • 7 comments

Describe the bug

When using cdk synth to bundle my lambda code (in python) CDK throws spawnSync docker ENOENT

Expected Behavior

cdk to look in the right location /Applications/Docker.app/Contents/Resources/bin/docker or look into possible locations.

Current Behavior

Currently cdk is looking at the wrong directory which caused the confusing error of spawnSync docker ENOENT

Reproduction Steps

OS: Macos 13.6.7 (22G720) Docker: Docker Desktop 4.31.0 (153195) CDK: 2.146.0 (b368c78)

new lambda.Function(this, 'myFn', {
      runtime: lambda.Runtime.PYTHON_3_12,
      handler: 'main.handler',
      code: lambda.Code.fromAsset(path.join(__dirname, './src'), {
        bundling: {
          image: lambda.Runtime.PYTHON_3_12.bundlingImage,
          command: [
            'bash', '-c',
            'pip install -r requirements.txt -t /asset-output && cp -au . /asset-output'
          ],
        },
      }),
    });

Possible Solution

ln -s '/Applications/Docker.app/Contents/Resources/bin/docker' '/usr/local/bin/docker'

This will solve the issue.

Additional Information/Context

No response

CDK CLI Version

2.146.0

Framework Version

No response

Node.js Version

v22.1.0

OS

Macos 13.6.7 (22G720)

Language

TypeScript

Language Version

No response

Other information

Searching for this message can be misleading as 99% of people suggesting installing esbuild and things related to that. But the point is this spawnSync xyz ENOENT just means the xyz is missing. I hope this will save some people some time. And the issue is fixed in future.

damshenas avatar Jun 17 '24 16:06 damshenas

Hi @damshenas , thanks for reaching out. I found previously filed similar issue-

Issue - https://github.com/aws/aws-cdk/issues/22997 Suggested solution - https://github.com/aws/aws-cdk/issues/22997#issuecomment-1372294374

Could you please check if this is the exact condition you are running into and the solution might help ??

khushail avatar Jun 17 '24 20:06 khushail

Hi @khushail, thanks for the follow up. Short answer is no, it does not help. Long answer is that, unfortunately the solution in the other issue does not fix my problem. In my case, there is nothing needed to be installed. Docker is already there but cdk can not find it. I also posted the solution that worked for me, but I think CDK can do better.

damshenas avatar Jun 17 '24 20:06 damshenas

Thanks @damshenas for the confirmation.

khushail avatar Jun 17 '24 21:06 khushail

@damshenas

I guess this is how CDK finds the docker CLI

https://github.com/aws/aws-cdk/blob/b196b13b0b8a54dcacadf87fdbe744772a6e6c4d/packages/cdk-assets/lib/private/docker.ts#L273-L275

Looks like it won't search /Applications/Docker.app/Contents/Resources/bin/docker

Can you try which docker and see if it returns /Applications/Docker.app/Contents/Resources/bin/docker?

And, is /Applications/Docker.app/Contents/Resources/bin in your $PATH?

pahud avatar Jun 18 '24 18:06 pahud

@pahud indeed that path is what which docker returns. It is not in the $PATH. I checked with another laptop (arm) and it also did not have it in the $PATH (but cdk worked fine there). Seems adding those directories to $PATH is not common in Mac.

Logically, adding the path to $PATH should also fix the issue. But ideally CDK should be able to work out of the box on all Macs.

damshenas avatar Jun 20 '24 08:06 damshenas

Hi @damshenas,

Thanks for reporting! This appears to be a duplicate issue. If you feel this is a distinct issue, please let us know in the comments. Otherwise, we'll close this ticket in 7 days and encourage you to follow the conversation threads in the potential duplicates listed below ranked by engagement.

Potential Duplicate Issues

  • #29883: Both issues report CDK failing to find the Docker executable during asset bundling operations with the error "spawnSync docker ENOENT", despite Docker being installed. In the current issue, Docker is installed at '/Applications/Docker.app/Contents/Resources/bin/docker' on macOS but isn't in PATH. Issue #29883 describes the identical root problem on Windows where Docker was installed but not in a location CDK checks. Both issues involve the same CDK bundling functionality and can be resolved by ensuring Docker is accessible through PATH or via symlinks.

This message was generated automatically to help connect related conversations and improve discoverability.

Please react with 👍 or 👎 to let us know if this response was helpful!

Thank you for helping improve CDK! 🙌

maintainer-for-aws avatar Aug 27 '25 11:08 maintainer-for-aws

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

github-actions[bot] avatar Aug 29 '25 12:08 github-actions[bot]