Repository navigation
Replies: 1 comment
|
As of the current Testcontainers for .NET API, I don't see direct support for passing multiple named BuildKit contexts equivalent to: docker buildx build There are two related APIs worth distinguishing: ImageFromDockerfileBuilder uses the Docker Engine API and supports a single build context through WithContextDirectory(...). BuildKitImageFromDockerfileBuilder uses docker buildx build and supports BuildKit-specific features such as secrets and SSH, but the builder currently does not appear to expose a WithBuildContext(name, path)-style API for named additional contexts. For this scenario, I would consider three approaches.
If keeping the Dockerfile unchanged is important, this is probably the cleanest option. Build the image before creating the Testcontainers container: docker buildx build Then let Testcontainers consume the resulting image: var container = new ContainerBuilder() await container.StartAsync(); This keeps the responsibility separated: Buildx
If the directory structure permits it, another option is moving the build context high enough in the directory tree and using: new ImageFromDockerfileBuilder() This is simpler operationally, although it is not equivalent to named BuildKit contexts and may require changing COPY paths or .dockerignore.
Architecturally, the most natural Testcontainers API would be something similar to: new BuildKitImageFromDockerfileBuilder("docker:...") which could translate internally to: --build-context abc=/path/to/context1 That would preserve the existing Dockerfile and keep image lifecycle management inside Testcontainers. So, for the current API, I would use external docker buildx build --load + ContainerBuilder.WithImage(...) when multiple named contexts are mandatory. If maintaining the Dockerfile unchanged is a hard requirement, that solution also avoids flattening or copying multiple source trees into a synthetic context. |
Uh oh!
There was an error while loading. Please reload this page.
I have a Dockerfile that uses multiple build contexts with the
COPY --from=<buildcontext>syntax. When building the image manually, I use thedocker buildcommand with the--build-contextflag, like this:docker build --build-context abc=/path/to/context1 --build-context xyz=/path/to/context2 -f Dockerfile .However, I'm now trying to use TestContainers for .NET to automate my testing, and I can't find a way to specify multiple build contexts when building an image with
ImageFromDockerfile.My Questions:
--build-contextfor multiple build contexts directly in TestContainers for .NET?I’d prefer to keep my Dockerfile unchanged, as modifying it to merge contexts isn't an ideal solution for my use case.
Thanks for any guidance!
All reactions