Skip to content

Commit 18bd825

Browse files
docs: add documentation about reusable containers
1 parent 52ce639 commit 18bd825

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

index.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,29 @@ When trying to launch a testcontainer from within a Docker container, e.g., in c
8585
1. The container has to provide a docker client installation. Either use an image that has docker pre-installed (e.g. the `official docker images <https://hub.docker.com/_/docker>`_) or install the client from within the `Dockerfile` specification.
8686
2. The container has to have access to the docker daemon which can be achieved by mounting `/var/run/docker.sock` or setting the `DOCKER_HOST` environment variable as part of your `docker run` command.
8787

88+
Reusable Containers (Experimental)
89+
----------------------------------
90+
91+
Containers can be reused across consecutive test runs.
92+
93+
How to use?
94+
^^^^^^^^^^^
95+
96+
1. Add `testcontainers.reuse.enable=true` to `~/.testcontainers.properties`
97+
2. Disable ryuk by setting the environment variable `TESTCONTAINERS_RYUK_DISABLED=true`
98+
3. Instantiate a container using `with_reuse`
99+
100+
.. doctest::
101+
102+
>>> from testcontainers.core.container import DockerContainer
103+
104+
>>> with DockerContainer("hello-world").with_reuse() as container:
105+
... first_id = container._container.id
106+
>>> with DockerContainer("hello-world").with_reuse() as container:
107+
... second_id == container._container.id
108+
>>> print(first_id == second_id)
109+
True
110+
88111
Configuration
89112
-------------
90113

0 commit comments

Comments
 (0)