testcontainers-rs
testcontainers-rs copied to clipboard
Add container function to get the gateway ip address
The container's gateway IP address is necessary for setups where your testcontainer runs inside another Docker container. Unfortunately, the bridge IP address doesn't coincide with the gateway address.
Looking forward to have this merged. Alternatively the inspect method could be made public for more flexibility.
Looking forward to have this merged. Alternatively the
inspectmethod could be made public for more flexibility.
This is unlikely going to happen as it would be a big commitment to the public API of testcontainers which I am reluctant to make.
@thomaseizinger thanks for taking the time to review this, and sorry for being so late.
For the first part of your questions. As far as I know the gateway IP corresponds to the actual bridge network address (the "router" so to speak) whilst the current implementation of get_bridge_ip_address is taking the IP address of the created container (within the bridge network).
As an example, if you take a look at the python implementation of testcontainers (here) you'll notice this is an issue as well when running a container within a container. Unfortunately, I'm not versed enough in docker networking to know the exact reason, but I can confirm that in practice this happens and if you don't point to the gateway address, your container won't be reached.
This actually links together nicely with your question regarding having a single function that returns a valid address, since python and java (see the relevant function here) versions of this lib seem to go for that approach. I would be happy to give that concept a whirl. Although, I have to admit I would like to simplify on what the python version does.
Regarding the missing adaption of ContainerAsync and changelog, I'm happy to add those once we agree on an approach.