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

Add container function to get the gateway ip address

Open jltorresm opened this issue 3 years ago • 1 comments

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.

jltorresm avatar Oct 07 '22 17:10 jltorresm

Looking forward to have this merged. Alternatively the inspect method could be made public for more flexibility.

ns-sjorgedeaguiar avatar Oct 09 '22 21:10 ns-sjorgedeaguiar

Looking forward to have this merged. Alternatively the inspect method 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 avatar Oct 31 '22 08:10 thomaseizinger

@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.

jltorresm avatar Dec 06 '22 19:12 jltorresm