Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equivalent to TestContainers.exposeHostPorts? #535

Open
hovinen opened this issue Nov 14, 2023 · 4 comments
Open

Equivalent to TestContainers.exposeHostPorts? #535

hovinen opened this issue Nov 14, 2023 · 4 comments

Comments

@hovinen
Copy link
Contributor

hovinen commented Nov 14, 2023

I'm working on a test which must expose a service running on the host to a service running in a container.

In Java, this can be done with Testcontainers.exposeHostPorts(localServerPort); as per https://java.testcontainers.org/features/networking/.

I am unable to find an equivalent to this functionality in the Rust crate. How can one do this?

@dezyh
Copy link

dezyh commented Dec 3, 2023

I recommend linking to the actual section which you're referring to so other people don't get confused like me.

@thomaseizinger
Copy link
Collaborator

I am unable to find an equivalent to this functionality in the Rust crate. How can one do this?

It is not supported at the moment. I am not familiar with the Java implementation in how they achieve this.

@mervyn-mccreight
Copy link
Contributor

I think this would indeed be very useful. I'll have a look at it when I find the time.

@DDtKey
Copy link
Collaborator

DDtKey commented Jun 4, 2024

In order to achieve similar behavior it's possible to use one of the following ways:

  • with_host("host.docker.internal" , Host::HostGateway)
    And after that you can try to use host.docker.internal:{host_port} from the container
  • use host network (however, this way you lose isolation of container's ports)

These options were initially suggested in our Slack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants