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

feat: Add network context manager

Open mloesch opened this issue 2 years ago • 5 comments

This PR adds a Network helper class that allows to create networks and connect containers programmatically.

The networks are context-managed resources like containers created via DockerContainer.

Please also see tests for a usage example :)

mloesch avatar Jul 05 '23 12:07 mloesch

I'm interested in this feature. But I see progress has been dropped. Is there a reason?

VerdantForge avatar Nov 10 '23 09:11 VerdantForge

I'm interested in this feature. But I see progress has been dropped. Is there a reason?

The build is failing due to https://github.com/cython/cython/issues/4568

I created #376 to fix it, but it hasn't been approved yet.

mloesch avatar Nov 10 '23 09:11 mloesch

Hey @mloesch, thanks for providing this PR for the feature. I see you decided to allow specifying a name for the Network. In Testcontainers for Java, we made the design decision to only generate networks with random names, to avoid the potential for naming conflicts with existing networks. This is a general design approach of Testcontainers and it should be fine for the Testcontainers use cases.

Would you like to adapt the implementation accordingly?

See https://github.com/testcontainers/testcontainers-java/blob/1a3b23385f9a595576246a4c7f5dc54d244dd69d/core/src/main/java/org/testcontainers/containers/Network.java for the Java implementation.

kiview avatar Nov 24 '23 19:11 kiview

Hey @kiview, thanks for the review, I changed the implementation to use random names in c10223fbec1d88755816c0ba9d2f77693816d822

mloesch avatar Nov 27 '23 10:11 mloesch

@kiview is there anything else required for this PR to be merged? :)

mloesch avatar Feb 06 '24 09:02 mloesch

Thank you for this @mloesch! 🙌 Really appreciate your contribution, this will benefit a lot of users 💯

santi avatar Apr 16 '24 10:04 santi