Skip to content

Commit

Permalink
Add networking documentation (#1651)
Browse files Browse the repository at this point in the history
* Add networking documentation

Resolves #1159

* Use code snippet from NetworkTest in networking documentation

Issue #1159

* Removed example no longer being used

Issue #1159
  • Loading branch information
mikesir87 authored and bsideup committed Jul 26, 2019
1 parent cde3d46 commit f9453dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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-->

0 comments on commit f9453dd

Please sign in to comment.