Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-ecr: Unable to execute 'docker' in order to build a container asset, even when docker is installed and available #29883

Open
NicholasACTran opened this issue Apr 18, 2024 · 7 comments
Labels
@aws-cdk/aws-ecr Related to Amazon Elastic Container Registry bug This issue is a bug. effort/medium Medium work item – several days of effort p3

Comments

@NicholasACTran
Copy link

Describe the bug

When attempting to deploy a test stack with a basic DockerImageAsset, it fails with the error: fail: Unable to execute 'docker' in order to build a container asset. Please install 'docker' and try again. Docker is installed, accessible via terminal, and the daemon is running.

Expected Behavior

This should deploy, or it should print out a more understandable error for triaging.

Current Behavior

Using the --verbose flag, the following trace log is outputted:

[01:01:47] CdkBatchS3GlueTestStack:  debug: docker login --username AWS --password-stdin https://{account-id}.dkr.ecr.us-east-1.amazonaws.com
CdkBatchS3GlueTestStack:  fail: Unable to execute 'docker' in order to build a container asset. Please install 'docker' and try again.

 ❌ Deployment failed: Error: Failed to build asset f866eee5216a683f77931e97f5616dadfe84d4da7a55d097eccb44128409caa0:current_account-current_region
    at Deployments.buildSingleAsset (C:\Users\nicho\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:436:11251)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.buildAsset (C:\Users\nicho\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:436:198136)
    at async C:\Users\nicho\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:436:181394
[01:01:47] Reading cached notices from C:\Users\nicho\.cdk\cache\notices.json

Failed to build asset f866eee5216a683f77931e97f5616dadfe84d4da7a55d097eccb44128409caa0:current_account-current_region
[01:01:47] Error: Failed to build asset f866eee5216a683f77931e97f5616dadfe84d4da7a55d097eccb44128409caa0:current_account-current_region
    at Deployments.buildSingleAsset (C:\Users\nicho\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:436:11251)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.buildAsset (C:\Users\nicho\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:436:198136)
    at async C:\Users\nicho\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:436:181394

This occurs even after running aws ecr get-login-password | docker login --username AWS --password-stdin https://{account-id}.dkr.ecr.us-east-1.amazonaws.com before cdk synth. Upon further testing, docker image build, and other docker commands work just fine running from the same terminal.

Reproduction Steps

At the core, the related ECR code for the stack is:

user = iam.User(self, 'User')
ecr.PublicGalleryAuthorizationToken.grant_read(user)
        
image = ecr_assets.DockerImageAsset(self, "TestBuildImage",
                                    directory="./src",
                                    cache_disabled=True)

The ./src folder, just contains a Dockerfile setup as follows:

FROM python

COPY test.py /


RUN pip install --upgrade pip && \
    pip install boto3 && \
    pip install boto 

RUN pwd
RUN ls

CMD ["python", "test.py"]

with the the test.py file being:

def main():
   print("Hello World")

if __name__ == '__main__':
   main()

Running aws ecr get-login-password | docker login --username AWS --password-stdin https://{account-id}.dkr.ecr.us-east-1.amazonaws.com before cdk synth can be an option, but doesn't seem to change behavior.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.137.0 (build bb90b4c)

Framework Version

No response

Node.js Version

v18.8.0

OS

Windows 10 Home Version 10.0.19045 Build 19045

Language

Python

Language Version

Python 3.10.7

Other information

No response

@NicholasACTran NicholasACTran added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 18, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ecr Related to Amazon Elastic Container Registry label Apr 18, 2024
@pahud
Copy link
Contributor

pahud commented Apr 18, 2024

This error indicates cdk can't find docker command in your $PATH.

Are you installing docker in a special directory? Is it in your system $PATH?

@pahud pahud added p2 effort/medium Medium work item – several days of effort response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Apr 18, 2024
@NicholasACTran
Copy link
Author

This error indicates cdk can't find docker command in your $PATH.

Are you installing docker in a special directory? Is it in your system $PATH?

docker is in my system $PATH. Did the normal Docker Desktop installation.
docker_env_variable

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Apr 18, 2024
@jaspersival
Copy link

Since yesterday, I have the same issue. It is very annoying, all the time thinking it is something about my CDK code or my Docker image in which I have installed the CDK. I have Docker Desktop also installed and I use WSL for running the container.

@mike-eh2
Copy link

mike-eh2 commented May 2, 2024

Same issue here.

I was wrong to assume that docker was in my $PATH just because I can execute it. It seems Docker Desktop does some sort of trickery to make docker executable in your shell without adding it to your $PATH. I realized this when which docker returned nothing. Adding docker to my path did the trick after all.

# in .bash_profile or .bashrc or .zshrc or whatever:
export PATH="$PATH:$HOME/.docker/bin"

(mac)

@pahud pahud added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 3, 2024
Copy link

github-actions bot commented Jun 3, 2024

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 github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 3, 2024
@NicholasACTran
Copy link
Author

This problem is still open. My workaround is to create a CodePipeline that reads from the repo and dockerizes the image and puts it into ECR. It's a PITA workaround though since dealing with Github permissions can be really annoying in Organizations where you're not an admin.

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jun 4, 2024
@pahud pahud added p3 and removed p2 labels Jun 11, 2024
@waltmayfield
Copy link

waltmayfield commented Sep 27, 2024

I'm having this same issue when publishing Docker images inside a CodeBuild environment. I'll have several successful builds, and then seemingly randomly it will stop working. I'm using AWS Amplify Gen2.

Here's the code snippet which creates a Lambda function backed by a docker image.

const queryReportImageLambdaPy = new lambda.DockerImageFunction(customStack, 'QueryReportImagesPy', {
  code: lambda.DockerImageCode.fromImageAsset(path.join(
      __dirname, 'functions', 'getInfoFromPdfPy'
  )),
  timeout: cdk.Duration.minutes(15),
  memorySize: 3000,
  role: queryReportsLambdaRole,
  environment: {
      'DATA_BUCKET_NAME': dataBucketName,
      // 'MODEL_ID': 'anthropic.claude-3-sonnet-20240229-v1:0',
      'MODEL_ID': 'anthropic.claude-3-haiku-20240307-v1:0',
      'MAX_TOKENS': '4096'
  }
});

Here's a snippet from the CodeBuild log:

2024-09-27T15:15:43.574Z [INFO]: # Executing command: npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID --debug
...
2024-09-27T15:16:04.360Z [INFO]: amplify-xxxxxxxxx-langGraph-branch-xxxxxxxxx: start: Publishing e1bae9e564e9e1e7bb3d16f1f14f5463e41a8defdaddf260deef78672fd4be66:current_account-current_region
2024-09-27T15:16:04.391Z [INFO]: [DEBUG] 2024-09-27T15:16:04.391Z: �[31mamplify-xxxxxxxx-langGraph-branch-xxxxxxxx: fail: Unable to execute 'docker' in order to build a container asset. Please install 'docker' and try again.�[39m

My issue may be related to the build image used by AWS Amplify:
https://discord.com/channels/705853757799399426/1282894735001784350/1282912750150094848

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecr Related to Amazon Elastic Container Registry bug This issue is a bug. effort/medium Medium work item – several days of effort p3
Projects
None yet
Development

No branches or pull requests

5 participants