withReuse method

GenericContainer withReuse(
  1. bool reuse
)

Keeps the container alive after the tests, for the next run to use again (off by default, and ignored when the CI environment variable is set).

The container is found again by a hash of its configuration (image, environment, command, ports, files and labels), so a changed configuration makes a new one. It carries no run id, so the reaper leaves it alone, and stop does not remove it: remove it by hand with docker rm -f $(docker ps -aq --filter label=org.testcontainers.reuse.hash). Use it for fast iterations on a laptop; the data inside survives, so tests must clean up after themselves.

Testcontainers (Java): withReuse(true), which also needs testcontainers.reuse.enable=true in ~/.testcontainers.properties.

Implementation

GenericContainer withReuse(bool reuse) {
  _reuse = reuse;
  return this;
}