Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs #950

Merged
merged 4 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions docs/features/containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ const container = await new GenericContainer("alpine")
.withAutoRemove(false)
.start();

await container.stop()
await container.stop();
```

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

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

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.


Volumes created by the container are removed when stopped. This is configurable:

```javascript
Expand Down Expand Up @@ -425,6 +428,22 @@ const container2 = await new GenericContainer("alpine")
expect(container1.getId()).toBe(container2.getId());
```

You can also re-use stopped but not removed containers.

```javascript
const container1 = await new GenericContainer("alpine")
.withReuse()
.withAutoRemove(false)
.start();
await container1.stop();

const container2 = await new GenericContainer("alpine")
.withReuse()
.start();

expect(container1.getId()).toBe(container2.getId());
```

Container re-use can be enabled or disabled globally by setting the `TESTCONTAINERS_REUSE_ENABLE` environment variable to `true` or `false`.
If this environment variable is not declared, the feature is enabled by default.

Expand Down
9 changes: 9 additions & 0 deletions docs/features/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ const container = await GenericContainer
.build();
```

### With platform

```javascript
const container = await GenericContainer
.fromDockerfile("/path/to/build-context")
.withPlatform("linux/amd64")
.build();
```

## Image name substitution

Testcontainers supports automatic substitution of Docker image names.
Expand Down
10 changes: 7 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
<a href="https://golang.testcontainers.org/" class="card-grid-item"><img src="/site/language-logos/go.svg"/>Go</a>
<a href="https://dotnet.testcontainers.org/" class="card-grid-item"><img src="/site/language-logos/dotnet.svg"/>.NET</a>
<a class="card-grid-item"><img src="/site/language-logos/nodejs.svg"/>Node.js</a>
<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>
<a href="https://github.com/testcontainers/testcontainers-elixir/" class="card-grid-item" ><img src="/site/language-logos/elixir.svg"/>Elixir</a>
<a href="https://github.com/testcontainers/testcontainers-hs/" class="card-grid-item"><img src="/site/language-logos/haskell.svg"/>Haskell</a>
<a href="https://testcontainers-python.readthedocs.io/en/latest/" class="card-grid-item"><img src="/site/language-logos/python.svg"/>Python</a>
<a href="https://docs.rs/testcontainers/latest/testcontainers/" class="card-grid-item"><img src="/site/language-logos/rust.svg"/>Rust</a>
<a class="card-grid-item" href="https://github.com/testcontainers/testcontainers-hs/"><img src="/site/language-logos/haskell.svg"/>Haskell</a>
<a href="https://github.com/testcontainers/testcontainers-ruby/" class="card-grid-item" ><img src="/site/language-logos/ruby.svg"/>Ruby</a>
<a href="https://docs.rs/testcontainers/latest/testcontainers/" class="card-grid-item"><img src="/site/language-logos/rust.svg"/>Rust</a>
<a href="https://github.com/testcontainers/testcontainers-php/" class="card-grid-item" ><img src="/site/language-logos/php.svg"/>PHP</a>
<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>
</div>

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

## Copyright

Copyright (c) 2018 - 2023 Cristian Greco and other authors.
Copyright (c) 2018 - 2025 Cristian Greco and other authors.

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

Expand Down
8 changes: 8 additions & 0 deletions docs/site/language-logos/clojure.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions docs/site/language-logos/elixir.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/site/language-logos/php.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions docs/site/language-logos/scala.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ describe("GenericContainer reuse", { timeout: 180_000 }, () => {
await container2.stop();
});

it("should reuse stopped container, if configured withAutoRemove(false)", async () => {
const name = `will_stop_and_reuse_again_${randomUuid()}`;
const container1 = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
.withName(name)
.withExposedPorts(8080)
.withReuse()
.withAutoRemove(false)
.start();
await container1.stop({ timeout: 10000 });

const container2 = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
.withName(name)
.withExposedPorts(8080)
.withReuse()
.start();
await checkContainerIsHealthy(container2);

expect(container1.getId()).toBe(container2.getId());
await container2.stop({ remove: true });
});

it("should reuse container when an existing reusable container has stopped but not removed", async () => {
const name = `there_can_only_be_one_${randomUuid()}`;
const container1 = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
Expand Down