aws-ecr: Unable to execute 'docker' in order to build a container asset, even when docker is installed and available
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### 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_
Contributor guide
Research direction
Reproduce the failure on Windows 10 with CDK CLI 2.137.0 using the provided DockerImageAsset and cdk synth. Inspect the CLI path that builds Docker assets after the ECR login trace; done means Docker is invoked successfully or the error identifies the actual failure, with coverage for the reported scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, docker, node.js, python, typescript
- Domain
- build-system, cli, cloud, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100