Give reusable containers a stable identity and a way to prune them

Open
#1,552 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
docker, node.js, typescript
Domain
devtools, testing

Research direction

Start by reading reuseOrStartContainer in packages/testcontainers/src/generic-container/generic-container.ts and createLabels in packages/testcontainers/src/utils/labels.ts, then review dependency issue #1522 to understand the shared reuse hash decision. The issue also calls for an optional reuse key and a prune API plus command; define how replacement handles containers used by another process. Done means identity stays stable across library upgrades, keyed configuration changes replace the old reusable container, and users can list or prune reusable containers.

Written by the indexing model from the issue text.

Description

enhancement minor

What happens

A reusable container lives until someone removes it by hand, and the library gives no help with that.

  • The reuse hash includes the org.testcontainers.version label, so every library upgrade changes the hash of every reusable container. The old ones are never matched again and keep running.
  • Any change to a container's configuration has the same effect: a new container appears next to the old one.
  • There is no API or command to list or remove reusable containers. The way to find them is docker ps --filter label=org.testcontainers.container-hash.

Expected

  • The library version is not part of a reusable container's identity.
  • An optional explicit key, withReuse({ key: "orders-db" }). A container with the same key and a different configuration is replaced instead of joined by a second one.
  • A way to clean up: TestContainers.pruneReusableContainers() and a matching command.

Where

  • reuseOrStartContainer in packages/testcontainers/src/generic-container/generic-container.ts
  • createLabels in packages/testcontainers/src/utils/labels.ts

Notes

  • Go has WithReuseByName(containerName).
  • Decide what "replace" means for a container another process is still using.

Dependencies

  • Stack on #1522: both redefine what goes into the reuse hash. Decide the contents once.
Dominant language
TypeScript
Stars
2.7k
Forks
290
Avg merge
4d 1h
Merged PRs (30d)
22

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from testcontainers/testcontainers-node

All issues in testcontainers/testcontainers-node

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.