Skip to content

Commit 6624fd2

Browse files
authored
Update docs (#950)
1 parent b19e0c8 commit 6624fd2

File tree

8 files changed

+144
-5
lines changed

8 files changed

+144
-5
lines changed

docs/features/containers.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ const container = await new GenericContainer("alpine")
355355
.withAutoRemove(false)
356356
.start();
357357

358-
await container.stop()
358+
await container.stop();
359359
```
360360

361361
The value specified to `.withAutoRemove()` can be overridden by `.stop()`:
@@ -365,9 +365,12 @@ const container = await new GenericContainer("alpine")
365365
.withAutoRemove(false)
366366
.start();
367367

368-
await container.stop({ remove: true }) // The container is stopped *AND* removed
368+
await container.stop({ remove: true }); // The container is stopped *AND* removed
369369
```
370370

371+
Keep in mind that disabling ryuk (set `TESTCONTAINERS_RYUK_DISABLED` to `true`) **and** disabling automatic removal of containers will make containers persist after you're done working with them.
372+
373+
371374
Volumes created by the container are removed when stopped. This is configurable:
372375

373376
```javascript
@@ -425,6 +428,22 @@ const container2 = await new GenericContainer("alpine")
425428
expect(container1.getId()).toBe(container2.getId());
426429
```
427430

431+
You can also re-use stopped but not removed containers.
432+
433+
```javascript
434+
const container1 = await new GenericContainer("alpine")
435+
.withReuse()
436+
.withAutoRemove(false)
437+
.start();
438+
await container1.stop();
439+
440+
const container2 = await new GenericContainer("alpine")
441+
.withReuse()
442+
.start();
443+
444+
expect(container1.getId()).toBe(container2.getId());
445+
```
446+
428447
Container re-use can be enabled or disabled globally by setting the `TESTCONTAINERS_REUSE_ENABLE` environment variable to `true` or `false`.
429448
If this environment variable is not declared, the feature is enabled by default.
430449

docs/features/images.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ const container = await GenericContainer
9191
.build();
9292
```
9393

94+
### With platform
95+
96+
```javascript
97+
const container = await GenericContainer
98+
.fromDockerfile("/path/to/build-context")
99+
.withPlatform("linux/amd64")
100+
.build();
101+
```
102+
94103
## Image name substitution
95104

96105
Testcontainers supports automatic substitution of Docker image names.

docs/index.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
<a href="https://golang.testcontainers.org/" class="card-grid-item"><img src="/site/language-logos/go.svg"/>Go</a>
77
<a href="https://dotnet.testcontainers.org/" class="card-grid-item"><img src="/site/language-logos/dotnet.svg"/>.NET</a>
88
<a class="card-grid-item"><img src="/site/language-logos/nodejs.svg"/>Node.js</a>
9+
<a href="https://cljdoc.org/d/clj-test-containers/clj-test-containers/0.7.4/doc/readme/" class="card-grid-item" ><img src="/site/language-logos/clojure.svg"/>Clojure</a>
10+
<a href="https://github.com/testcontainers/testcontainers-elixir/" class="card-grid-item" ><img src="/site/language-logos/elixir.svg"/>Elixir</a>
11+
<a href="https://github.com/testcontainers/testcontainers-hs/" class="card-grid-item"><img src="/site/language-logos/haskell.svg"/>Haskell</a>
912
<a href="https://testcontainers-python.readthedocs.io/en/latest/" class="card-grid-item"><img src="/site/language-logos/python.svg"/>Python</a>
10-
<a href="https://docs.rs/testcontainers/latest/testcontainers/" class="card-grid-item"><img src="/site/language-logos/rust.svg"/>Rust</a>
11-
<a class="card-grid-item" href="https://github.com/testcontainers/testcontainers-hs/"><img src="/site/language-logos/haskell.svg"/>Haskell</a>
1213
<a href="https://github.com/testcontainers/testcontainers-ruby/" class="card-grid-item" ><img src="/site/language-logos/ruby.svg"/>Ruby</a>
14+
<a href="https://docs.rs/testcontainers/latest/testcontainers/" class="card-grid-item"><img src="/site/language-logos/rust.svg"/>Rust</a>
15+
<a href="https://github.com/testcontainers/testcontainers-php/" class="card-grid-item" ><img src="/site/language-logos/php.svg"/>PHP</a>
16+
<a href="https://github.com/testcontainers/testcontainers-scala/" class="card-grid-item" ><img style="width:30px; height:30px" src="/site/language-logos/scala.svg"/>Scala</a>
1317
</div>
1418

1519
## About
@@ -22,7 +26,7 @@ See [LICENSE](https://raw.githubusercontent.com/testcontainers/testcontainers-no
2226

2327
## Copyright
2428

25-
Copyright (c) 2018 - 2023 Cristian Greco and other authors.
29+
Copyright (c) 2018 - 2025 Cristian Greco and other authors.
2630

2731
See [contributors](https://github.com/testcontainers/testcontainers-node/graphs/contributors/) for contributors.
2832

Lines changed: 8 additions & 0 deletions
Loading
Lines changed: 47 additions & 0 deletions
Loading

docs/site/language-logos/php.svg

Lines changed: 5 additions & 0 deletions
Loading

docs/site/language-logos/scala.svg

Lines changed: 26 additions & 0 deletions
Loading

packages/testcontainers/src/generic-container/generic-container-reuse.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,27 @@ describe("GenericContainer reuse", { timeout: 180_000 }, () => {
129129
await container2.stop();
130130
});
131131

132+
it("should reuse stopped container, if configured withAutoRemove(false)", async () => {
133+
const name = `will_stop_and_reuse_again_${randomUuid()}`;
134+
const container1 = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
135+
.withName(name)
136+
.withExposedPorts(8080)
137+
.withReuse()
138+
.withAutoRemove(false)
139+
.start();
140+
await container1.stop({ timeout: 10000 });
141+
142+
const container2 = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
143+
.withName(name)
144+
.withExposedPorts(8080)
145+
.withReuse()
146+
.start();
147+
await checkContainerIsHealthy(container2);
148+
149+
expect(container1.getId()).toBe(container2.getId());
150+
await container2.stop({ remove: true });
151+
});
152+
132153
it("should reuse container when an existing reusable container has stopped but not removed", async () => {
133154
const name = `there_can_only_be_one_${randomUuid()}`;
134155
const container1 = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")

0 commit comments

Comments
 (0)