Skip to content
Closed
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
21 changes: 21 additions & 0 deletions docs/features/containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 5 additions & 1 deletion docs/features/wait-strategies.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:

Expand Down