Fix Dockerfile not located when added to dockerignore #2272
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
When the user adds
Dockerfile
to the.dockerignore
file,testcontainers
is not able to build the image with error:Error response from daemon: Cannot locate specified Dockerfile
This is because
testcontainers
doesn't include theDockerfile
to thebuildcontext
on purpose, it only expects to do so, if it is not included on theignorefile
. The docker client doesn't this either, the Docker cli is aware of this and maintainers have addressed this limitation in this PR long ago as the have tweaked the client to include both files to the build context.To fix this, I added the
.dockerignore
file in the current context and the targetDockefile
to the Build Context.archive.TarOptions
struct has a key on it to include files to the archive:Why is it important?
The motivation is that some developers don't want to include the
Dockerfile
to the result image to keep it as minimal as possible.Related issues
Closes #2203