docker assets: cannot build docker images outside the source tree (i.e. against a cdk.out directory)
See original GitHub issueThe feature to support customizing the docker file name introduced in #5652 will pass the full absolute path of the docker file name to docker build
. This happens both for the case where a custom docker file name is specified and when it is not specified (defaults to /full/path/to/Dockerfile
).
However, since we are staging the build directory into cdk.out
(which can potentially be ported to a different system, e.g. as part of a CI/CD process), we need the name of the custom docker file to be relative and not absolute.
See https://github.com/aws/aws-cdk/pull/5652/files#r366863153
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
aws-cdk/aws-ecr-assets module - AWS Documentation
Images are built from a local Docker context directory (with a Dockerfile ), uploaded to Amazon Elastic Container Registry (ECR) by the CDK...
Read more >How to include files outside of Docker's build context?
The best way to work around this is to specify the Dockerfile independently of the build context, using -f. For instance, this command...
Read more >cdk 1.21.0 on Node.js Yarn - NewReleases.io
docker assets : cannot build docker images outside the source tree (i.e. against a cdk.out directory) #5807; cli: cdk init fails if run...
Read more >Dockerized build environments for C/C++ projects
In this post, I will share how to create a docker-based build environment for C and C++ projects targeted for Linux.
Read more >Automating Docker Builds With Gradle - Tom Gregory
In this article you'll discover one of the best approaches I've found to automate Docker in your project. It's to create tasks for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @MrJonBirch. Let me clarify what exactly is happening.
Like you mentioned, during
synth
, theContainerImage
validates that theDockerfile
actually exists. After this validation passes, thecdk.out
directory is created by copying the necessary files from the asset configuration. Its here where the.dockerignore
file is processed, which caused theDockerfile
not to be copied intocdk.out
.During
cdk deploy
, thecdk
cli does not use the original path to theDockerfile
, but rather assumes that theDockerfile
exists inside thecdk.out
directory. This behavior is intentional, to make thecdk.out
directory self-contained and portable across machines and environments.You are right that this is actually an undocumented feature/behavior. I can point you to the following issues to get more context, and will make sure we add this to the documentation.
Hope this helps, and thanks!
@iliapolo thanks for the explanation above. I haven’t seen anything like it in the documentation. It helped me focus on cdk.out for the problem, but I wasn’t able to solve mine with just that information. My .dockerignore file looks like this:
so I don’t want to copy anything else over to the docker context besides the jar, but it is actually not copied over to cdk.out.![Screenshot 2021-03-16 at 14 28 05](https://user-images.githubusercontent.com/40452559/111332537-2d56f780-8672-11eb-8245-d05e7f98d3b8.png)
I have tried different variations to get the jar copied over, but nothing worked besides moving the jar to the root of the project instead of having it in a directory which is not realistic. Because of this the COPY command in the Dockerfile fails.
Any ideas how I could get the jar copied over so
docker build
completes fine?