Skip to content

Commit b48a0fd

Browse files
eddumelendezbsideupkiview
authored
Add documentation for reusable containers (#6216)
Reusable containers is an experimental features and docs should address questions around `what is it?` and `how to enable it?` Co-authored-by: Sergei Egorov <[email protected]> Co-authored-by: Kevin Wittek <[email protected]>
1 parent 8b92d14 commit b48a0fd

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

docs/features/reuse.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Reusable Containers (Experimental)
2+
3+
!!! warning
4+
Reusable Containers is still an experimental feature and the behavior can change.
5+
Those containers won't stop after all tests are finished.
6+
7+
The *Reusable Containers* feature keeps the containers running between test sessions. In order
8+
to use it, manual container lifecycle instrumentation should be used by calling the `start()` method
9+
and it needs to be manually enabled through an opt-in mechanism. In order to reuse a container, the
10+
configuration of the container *must not change*.
11+
12+
!!! note
13+
Reusable containers are not suited for CI usage and as an experimental feature
14+
not all Testcontainers features are fully working (e.g., resource cleanup
15+
or networking).
16+
17+
## How to use it
18+
19+
* Define a container with `withReuse(true)`
20+
21+
```java
22+
GenericContainer container = new GenericContainer("redis:6-alpine")
23+
.withExposedPorts(6379)
24+
.withReuse(true)
25+
```
26+
27+
* Opt-in to Reusable Containers in `~/.testcontainers.properties`, by adding `testcontainers.reuse.enable=true`
28+
* Containers need to be started manually using `container.start()`. See [docs](../../test_framework_integration/manual_lifecycle_control)
29+
30+
### Reusable Container with Testcontainers JDBC URL
31+
32+
If using the [Testcontainers JDBC URL support](../../modules/databases/jdbc#database-containers-launched-via-jdbc-url-scheme)
33+
the URL **must** follow the pattern of `jdbc:tc:mysql:5.7.34:///databasename?TC_REUSABLE=true`. `TC_REUSABLE=true` is set as a parameter of the JDBC URL.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ nav:
4242
- features/configuration.md
4343
- features/image_name_substitution.md
4444
- features/advanced_options.md
45+
- features/reuse.md
4546
- Modules:
4647
- Databases:
4748
- modules/databases/index.md

0 commit comments

Comments
 (0)