Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docker assets: cannot build docker images outside the source tree (i.e. against a cdk.out directory)

See original GitHub issue

The 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.


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

iliapolocommented, Jan 20, 2020

Hi @MrJonBirch. Let me clarify what exactly is happening.

Like you mentioned, during synth, the ContainerImage validates that the Dockerfile actually exists. After this validation passes, the cdk.out directory is created by copying the necessary files from the asset configuration. Its here where the .dockerignore file is processed, which caused the Dockerfile not to be copied into cdk.out.

During cdk deploy, the cdk cli does not use the original path to the Dockerfile, but rather assumes that the Dockerfile exists inside the cdk.out directory. This behavior is intentional, to make the cdk.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!

mimozellcommented, Mar 16, 2021

@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

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?

Read more comments on GitHub >

github_iconTop 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 -
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found