testcontainers / testcontainers-dotnet

A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
https://dotnet.testcontainers.org
MIT License
3.76k stars 271 forks source link

[Enhancement]: Use existing container (if it already exists) even if it was not created by TestContainers #1206

Open InspiringCode opened 3 months ago

InspiringCode commented 3 months ago

Problem

I have a container with a SQL Server that is quite resource hungry. I want to share the same docker container for my tests and for local development (F5). For local development I intent to use docker compose to start up the container. Using WithReuse doesn't work in this case, even if I manually add a reuse-id to my compose.yaml, because TestContainers always checks if a container with the reuse hash exists. In my case it tries to create a new container which results in a 409 Conflict being returned by docker.

Solution

Ideally I would be able to point to my compose.yaml file and TestContainers would just run docker compose up and wait for the container to be up and running.

But since this feature request is not really making progress, I am wondering if there is any way to achieve a similar result? Would it make sense to add an option to ignore the reuse hash?

Benefit

I some cases one really wants to share an environment between local dev and unit tests. This feature would enable this scenario.

Alternatives

One would theoretically reference the TestContainers assembly also in the production ASP.NET Core application (maybe with a "Is Debug Build" condition) and also call the ContainerBuilder there. But I am really not sure if this is a good idea?

Would you like to help contributing this enhancement?

No