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

Can't run MockServerContainer with withNetworkMode("host") #4286

Closed
yaseco opened this issue Jul 16, 2021 · 4 comments
Closed

Can't run MockServerContainer with withNetworkMode("host") #4286

yaseco opened this issue Jul 16, 2021 · 4 comments

Comments

@yaseco
Copy link

yaseco commented Jul 16, 2021

Consider the following test:

    @Test
    public void test() {
        MockServerContainer mock = new MockServerContainer("5.11.2")
                .withNetworkMode("host");

        mock.setPortBindings(List.of("1080:3333"));
        mock.start();
        
        while (true) {} // hang
    }

The error I'm getting is:
java.lang.IllegalArgumentException: Requested port (1080) is not mapped

btw, I don't mind about the exact port from the host perspective (in my case, 3333)
It could be arbitrary

Why do I get this error?

@guss77
Copy link
Contributor

guss77 commented Jul 26, 2021

I get the same error with release 1.16 when asking for a port mapped from the container.

Example code:

public class MyContainer extends GenericContainer<MyContainer> {

	public MyContainer () {
		super("some-image");
		withCreateContainerCmdModifier(c -> c
				.withExposedPorts(new ExposedPort(8088, InternetProtocol.TCP)));
	}

	public String getApiURL() {
		return "http://"+ this.getContainerIpAddress()+ ":" + this.getMappedPort(8088) + "/"; // <-- thrown here
	}
//...
}

This works well in release 1.15.3, but broke since the 1.16 release.

@bsideup
Copy link
Member

bsideup commented Jul 26, 2021

@guss77 in 1.16.0, we no longer publish all ports, so your exposed port isn't published anymore and you need to publish it yourself.

There is GenericContainer#withExposedPorts that will do this for you tho, and, in general, you don't need withCreateContainerCmdModifier here.

@aidando73
Copy link
Contributor

@yaseco

Testcontainers doesn't network mode host currently.

There's still some discussion going around surrounding that. See #5151. The main concern atm, is that it's a platform dependent change (network mode "host" only works on linux).

Though I'd like to learn more about your use-case with network mode "host"? What are you planning to use it for?

@eddumelendez
Copy link
Member

Closing due to a decision was made in #5151. See this comment.

@eddumelendez eddumelendez closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2023
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