Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package generic;

import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;

import static org.junit.Assert.assertTrue;

public class DependsOnTest {

@Rule
// dependsOn {
public GenericContainer<?> redis = new GenericContainer<>("redis:3.0.2").withExposedPorts(6379);

@Rule
public GenericContainer<?> nginx = new GenericContainer<>("nginx:1.9.4").dependsOn(redis).withExposedPorts(80);

// }

@Test
public void testContainersAllStarted() {
assertTrue(redis.isRunning());
assertTrue(nginx.isRunning());
}
}
8 changes: 8 additions & 0 deletions docs/features/startup_and_waits.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,11 @@ If none of these options meet your requirements, you can create your own subclas
/startupcheck/StartupCheckStrategy.html) with an appropriate startup check mechanism in `waitUntilStartupSuccessful()`.
Or you can leave it as is and just implement the `checkStartupState(DockerClient dockerClient, String containerId)` if you still want to check state
periodically.

## Depending on another container

Sometimes, a container relies on another container to be ready before it should start itself. An example of this might be a database that needs to be started before your application container can link to it. You can tell a container that it depends on another container by using the `dependsOn` method:

<!--codeinclude-->
[Depending on another container](../examples/junit4/generic/src/test/java/generic/DependsOnTest.java) inside_block:dependsOn
<!--/codeinclude-->