From ce02b3e32a410918077ddb1e83698904085852ae Mon Sep 17 00:00:00 2001 From: digital88 Date: Fri, 21 Mar 2025 23:40:58 +0300 Subject: [PATCH 1/4] (docs): minor additions --- docs/features/containers.md | 23 +++++++++++++++++-- docs/features/images.md | 9 ++++++++ docs/index.md | 8 +++++-- .../generic-container-reuse.test.ts | 21 +++++++++++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/docs/features/containers.md b/docs/features/containers.md index 288fe3700..40a524058 100644 --- a/docs/features/containers.md +++ b/docs/features/containers.md @@ -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()`: @@ -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 done working with them. + + Volumes created by the container are removed when stopped. This is configurable: ```javascript @@ -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. diff --git a/docs/features/images.md b/docs/features/images.md index f5cd6d434..fc4083b82 100644 --- a/docs/features/images.md +++ b/docs/features/images.md @@ -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. diff --git a/docs/index.md b/docs/index.md index 8bff16d63..c8f725010 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,8 +8,12 @@ Node.js Python Rust - Haskell + Haskell Ruby + Clojure + Elixir + PHP + Scala ## About @@ -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. diff --git a/packages/testcontainers/src/generic-container/generic-container-reuse.test.ts b/packages/testcontainers/src/generic-container/generic-container-reuse.test.ts index 785d92733..b54f521d7 100644 --- a/packages/testcontainers/src/generic-container/generic-container-reuse.test.ts +++ b/packages/testcontainers/src/generic-container/generic-container-reuse.test.ts @@ -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") From f7b1abcc7f1a96a097b4770a0767e76b0844a06f Mon Sep 17 00:00:00 2001 From: digital88 Date: Fri, 21 Mar 2025 23:48:01 +0300 Subject: [PATCH 2/4] add missing svgs --- docs/index.md | 10 +++--- docs/site/language-logos/clojure.svg | 8 +++++ docs/site/language-logos/elixir.svg | 47 ++++++++++++++++++++++++++++ docs/site/language-logos/php.svg | 5 +++ 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 docs/site/language-logos/clojure.svg create mode 100644 docs/site/language-logos/elixir.svg create mode 100644 docs/site/language-logos/php.svg diff --git a/docs/index.md b/docs/index.md index c8f725010..9aaffc4b3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -6,13 +6,13 @@ Go .NET Node.js - Python - Rust + Clojure + Elixir Haskell + Python Ruby - Clojure - Elixir - PHP + Rust + PHP Scala diff --git a/docs/site/language-logos/clojure.svg b/docs/site/language-logos/clojure.svg new file mode 100644 index 000000000..506db3b7d --- /dev/null +++ b/docs/site/language-logos/clojure.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/docs/site/language-logos/elixir.svg b/docs/site/language-logos/elixir.svg new file mode 100644 index 000000000..532746a46 --- /dev/null +++ b/docs/site/language-logos/elixir.svg @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/site/language-logos/php.svg b/docs/site/language-logos/php.svg new file mode 100644 index 000000000..939f1ec40 --- /dev/null +++ b/docs/site/language-logos/php.svg @@ -0,0 +1,5 @@ + + + + + From 1265eaf558d14e8e25b28bd79afc34d90f986bc5 Mon Sep 17 00:00:00 2001 From: digital88 <10961828+digital88@users.noreply.github.com> Date: Sat, 22 Mar 2025 00:32:28 +0300 Subject: [PATCH 3/4] Update docs/features/containers.md typo Co-authored-by: Cristian Greco --- docs/features/containers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/features/containers.md b/docs/features/containers.md index 40a524058..16afa5f38 100644 --- a/docs/features/containers.md +++ b/docs/features/containers.md @@ -368,7 +368,7 @@ const container = await new GenericContainer("alpine") 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 done working with them. +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: From 610233433a2fee22efd2bf71b30ee6b2b1a719ba Mon Sep 17 00:00:00 2001 From: digital88 Date: Sat, 22 Mar 2025 18:09:02 +0300 Subject: [PATCH 4/4] add scala logo --- docs/index.md | 2 +- docs/site/language-logos/scala.svg | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 docs/site/language-logos/scala.svg diff --git a/docs/index.md b/docs/index.md index 9aaffc4b3..d0ecd9390 100644 --- a/docs/index.md +++ b/docs/index.md @@ -13,7 +13,7 @@ Ruby Rust PHP - Scala + Scala ## About diff --git a/docs/site/language-logos/scala.svg b/docs/site/language-logos/scala.svg new file mode 100644 index 000000000..23decc05f --- /dev/null +++ b/docs/site/language-logos/scala.svg @@ -0,0 +1,26 @@ + + + + + Scala + The Scala Logo + + + + + + + + + + + + + + + + + + + + \ No newline at end of file