Skip to content

Commit bff1e3b

Browse files
docs: add documentation about reusable containers
1 parent ce3e3b4 commit bff1e3b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

index.rst

+22-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ When trying to launch Testcontainers from within a Docker container, e.g., in co
8989
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.
9090
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.
9191

92-
9392
Private Docker registry
9493
-----------------------
9594

@@ -118,6 +117,28 @@ Fetching passwords from cloud providers:
118117
GCP_PASSWORD = $(gcloud auth print-access-token)
119118
AZURE_PASSWORD = $(az acr login --name <registry-name> --expose-token --output tsv)
120119
120+
Reusable Containers (Experimental)
121+
----------------------------------
122+
123+
Containers can be reused across consecutive test runs.
124+
125+
How to use?
126+
^^^^^^^^^^^
127+
128+
1. Add `testcontainers.reuse.enable=true` to `~/.testcontainers.properties`
129+
2. Disable ryuk by setting the environment variable `TESTCONTAINERS_RYUK_DISABLED=true`
130+
3. Instantiate a container using `with_reuse`
131+
132+
.. doctest::
133+
134+
>>> from testcontainers.core.container import DockerContainer
135+
136+
>>> with DockerContainer("hello-world").with_reuse() as container:
137+
... first_id = container._container.id
138+
>>> with DockerContainer("hello-world").with_reuse() as container:
139+
... second_id == container._container.id
140+
>>> print(first_id == second_id)
141+
True
121142

122143
Configuration
123144
-------------

0 commit comments

Comments
 (0)