diff --git a/docs/features/containers.md b/docs/features/containers.md index 43bbbb0ce..ac3d7bce7 100644 --- a/docs/features/containers.md +++ b/docs/features/containers.md @@ -202,6 +202,27 @@ const container = await new GenericContainer("alpine") .start(); ``` +### With a wait strategy + +A wait strategy will resolve the call to `.start()` only when a start condition is met. This allows you to ensure the container can perform its work before resolving. + +A strategy can be a single condition or a composition of a few conditions. Here is an example of the latter: + +```javascript +import { GenericContainer, Wait } from "testcontainers"; + +const container = await new GenericContainer("my-upstream-service") + .withExposedPorts(3000) + .withWaitStrategy(Wait.forAll([ + Wait.forListeningPorts(), + Wait.forLogMessage(/server started on port/), + Wait.forHealthCheck(), + ])) + .start(); +``` + +There are many built-in wait strategies, supporting varying conditions, or you can write your own. For more info - see [wait Strategies](../wait-strategies). + ### With default log driver May be necessary when the driver of your docker host does not support reading logs, and you want to use the [log output wait strategy](../wait-strategies#log-output). diff --git a/docs/features/wait-strategies.md b/docs/features/wait-strategies.md index e396229c8..077d799a5 100644 --- a/docs/features/wait-strategies.md +++ b/docs/features/wait-strategies.md @@ -1,5 +1,9 @@ # Wait Strategies +A wait strategy will resolve the call to `container.start()` only after a condition is met. This allows you to ensure the container can perform its work before resolving. + +There are many built-in wait strategies, supporting varying conditions, which are listed below. + Note that the startup timeout of all wait strategies is configurable: ```javascript @@ -234,7 +238,7 @@ const w2 = Wait.forLogMessage("READY"); const composite = Wait.forAll([w1, w2]).withDeadline(2000); ``` -## Other startup strategies +## Custom Wait Strategies If these options do not meet your requirements, you can subclass `StartupCheckStrategy` and use `Dockerode`, which is the underlying Docker client used by Testcontainers: