mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Unable to build WireMockContainerBuilder with custom image #730
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @OliBomby on GitHub (Dec 9, 2025).
Originally assigned to: @StefH on GitHub.
Describe the bug
Custom WireMock images that include their own mappings like from the guide can not be used in
WireMockContainerBuilder.WithImage()leading to aInvalidOperationExceptiononBuild()because_imageOSis never set.Expected behavior:
I expect with the above code to work an not throw an exception. However after
WithLinuxImage()_imageOSis still set tonullbecause the builder objects gets recreated from scratch with only the docker config remaining.@StefH commented on GitHub (Dec 9, 2025):
@OliBomby
Please note that this project is related to WireMock.Net , the manual you reference is for wiremock (the Java docker version).
This will not work.
@OliBomby commented on GitHub (Dec 9, 2025):
Ah I did not realize there was a distinction in the WireMock version used in this Docker image.
I still think it should work though. It almost works just like this, if it didn't throw the
InvalidOperationExceptionthe rest of my code would've worked. The REST API of the Java and .NET versions of WireMock are almost the same.Here's a minimal working example of using the Java image in a .NET test container:
This code would be much cleaner if I could make use of the
WireMockContainerBuilderandWireMockContainerclasses, so that would be really nice to have.@StefH commented on GitHub (Dec 10, 2025):
@OliBomby
I understand your question. Currently, it's indeed not possible to provide a custom WireMock.Net or wiremock-org (java) image.
I can try to add that logic.
However, the mappings are not 100% the same, so using the
container.CreateClient();will not work correct for you.The best would be that I create a new NuGet named
WireMock.Org.Testcontainerswhich will use a default java docker image and also provide code to provide your own custom image.@StefH commented on GitHub (Dec 11, 2025):
I did fix it for
WireMock.Net.Testcontainers--> https://github.com/wiremock/WireMock.Net/pull/1391@StefH commented on GitHub (Dec 11, 2025):
The
WireMock.Net.Testcontainersis updated to accept a custom image and set the_imageOS.I will publish a new NuGet soon.
However, I cannot give any guarantee that this works for the wiremock java version.
@OliBomby commented on GitHub (Dec 11, 2025):
I'm afraid this implementation still won't work for any image which doesn't have
wiremock.netin the name, because_imageOSwill still benullin the builder object returned byWithCustomImage, because thebase.WithImagemethod creates a new builder object and doesn't retain the value for_imagesOS.3f9de427b8/src/Testcontainers/Builders/ContainerBuilder%603.cs (L93-L96)e3e2dc7c65/src/WireMock.Net.Testcontainers/WireMockContainerBuilder.cs (L281-L284)@StefH commented on GitHub (Dec 11, 2025):
I see
@StefH commented on GitHub (Dec 11, 2025):
https://github.com/wiremock/WireMock.Net/pull/1392