Multiple container networks
Hi 👋
I am experimenting with this project to use it as part of our test infrastructure with Playwright. So far, it's working well and has significantly helped us simplify our orchestration layer!
Is there any way for us to add a container to multiple networks? In compose terms, I am thinking of something like this:
networks:
network-a:
network-b:
services:
mssql:
networks:
network-a:
aliases:
- alias-mssql-a
service-a:
networks:
network-a:
aliases:
- alias-service-a
network-b:
aliases:
- alias-service-a
service-b:
networks:
network-b:
aliases:
- alias-service-b
The reason for this is that we only want to start mssql once for all test suites, and an instance of service-a and service-b per test.
The idea is that all instances of service-a will be connected to the mssql network, and each service-b will be connected to its current service-a's network.
Keen to get your thoughts on this 🙂
Hi, that's great. It is possible to connect a container to multiple networks, though it's not a method on the GenericContainer. We have an example here:
https://github.com/testcontainers/testcontainers-node/blob/08da47baeaa9a43f29aec3a9bb1ce67a3bc1849f/packages/testcontainers/src/generic-container/generic-container.ts#L161
Testcontainers exposes the underlying container runtime, so you can get your own instance of the client and do the same .
Nice! That works well for my case, thanks for the pointer 👌