testcontainers-cpp 0.2.0
Native C++20 Testcontainers over the Docker Engine API
Loading...
Searching...
No Matches
testcontainers::RestartPolicy Struct Reference

A daemon-side restart policy (HostConfig.RestartPolicy): when the container exits, the daemon itself restarts it. More...

#include <testcontainers/RestartPolicy.hpp>

Static Public Member Functions

static RestartPolicy always ()
 Restart whenever the container exits, regardless of exit code.
static RestartPolicy unless_stopped ()
 Like always(), except an explicit stop (docker stop) sticks.
static RestartPolicy on_failure (int max_retries)
 Restart only after a nonzero exit, giving up after max_retries consecutive failures (0 = no cap).

Public Attributes

std::string name
 Docker's Name values: "no", "always", "unless-stopped", "on-failure".
int maximum_retry_count = 0
 Give-up threshold after consecutive failed restarts; only valid nonzero with "on-failure" (0 = keep retrying without a cap).

Detailed Description

A daemon-side restart policy (HostConfig.RestartPolicy): when the container exits, the daemon itself restarts it.

Build one via the named factories, e.g. RestartPolicy::on_failure(3).

Two interactions worth knowing in test code: the daemon rejects a restart policy combined with auto-remove, and a restarting container is still Ryuk-reaped at process exit — always() keeps a crashing service alive DURING the test session, it does not outlive it (combine with reuse for a container that survives across runs).

Member Function Documentation

◆ always()

RestartPolicy testcontainers::RestartPolicy::always ( )
inlinestatic

Restart whenever the container exits, regardless of exit code.

◆ unless_stopped()

RestartPolicy testcontainers::RestartPolicy::unless_stopped ( )
inlinestatic

Like always(), except an explicit stop (docker stop) sticks.

◆ on_failure()

RestartPolicy testcontainers::RestartPolicy::on_failure ( int max_retries)
inlinestatic

Restart only after a nonzero exit, giving up after max_retries consecutive failures (0 = no cap).

Member Data Documentation

◆ name

std::string testcontainers::RestartPolicy::name

Docker's Name values: "no", "always", "unless-stopped", "on-failure".

◆ maximum_retry_count

int testcontainers::RestartPolicy::maximum_retry_count = 0

Give-up threshold after consecutive failed restarts; only valid nonzero with "on-failure" (0 = keep retrying without a cap).