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

Add networking documentation #1651

Merged
merged 3 commits into from Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,6 +5,7 @@
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.Network;

import static org.rnorth.visibleassertions.VisibleAssertions.*;
import static org.testcontainers.containers.Network.newNetwork;
Expand Down Expand Up @@ -39,8 +40,9 @@ public static class WithoutRules {

@Test
public void testNetworkSupport() throws Exception {
// useCustomNetwork {
try (
Network network = newNetwork();
Network network = Network.newNetwork();

GenericContainer foo = new GenericContainer()
.withNetwork(network)
Expand All @@ -57,6 +59,7 @@ public void testNetworkSupport() throws Exception {
String response = bar.execInContainer("wget", "-O", "-", "http://foo:8080").getStdout();
assertEquals("received response", "yay", response);
}
// }
}

@Test
Expand Down
12 changes: 12 additions & 0 deletions docs/features/networking.md
Expand Up @@ -75,3 +75,15 @@ For example, here we construct an HTTP URL for our local web application and tel
<!--codeinclude-->
[Accessing the exposed host port from a container](../examples/src/test/java/generic/HostPortExposedTest.java) inside_block:useHostExposedPort
<!--/codeinclude-->


## Advanced networking

Docker provides the ability for you to create custom networks and place containers on one or more networks. Then, communication can occur between networked containers without the need of exposing ports through the host. With Testcontainers, you can do this as well.

!!! warning
Note that Testcontainers currently only allows a container to be on a single network.

<!--codeinclude-->
[Creating custom networks](../../core/src/test/java/org/testcontainers/containers/NetworkTest.java) inside_block:useCustomNetwork
<!--/codeinclude-->