testcontainers-dotnet icon indicating copy to clipboard operation
testcontainers-dotnet copied to clipboard

Re-use existing networks

Open fdw opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe. For complicated reasons, our tests already run in a Docker container. From there, we want to use testcontainers to start a sibling container. While this works fine, we need to connect both to the same network so that the testcontainer is reachable. Unfortunately, as far as we can see, we can only connect it to an existing network if we know the network's ID (which we don't, as it is re-created regularly).

Describe the solution you'd like It should be possible to connect a testcontainer to a network using only the network's name.

Describe alternatives you've considered It might be possible to use some other Docker library to find the ID of the network so that we can pass it to testcontainers. But that is a lot of work.

fdw avatar Jul 29 '22 08:07 fdw

This is not yet supported and relates to #506#407 too. I haven't thought much about alternatives, but I think we need something similar. Maybe we can use the AbstractBuilder to provide this feature for all Docker resources.

HofmeisterAn avatar Jul 29 '22 10:07 HofmeisterAn

Since we refactored and moved to the new container builder API, this is now possible. You can use WithNetwork(string) to connect to an already existing network. In addition, we extended the reuse support by implementing #1051.

HofmeisterAn avatar Jan 20 '24 16:01 HofmeisterAn