Skip to content

Conversation

@edrevo
Copy link
Contributor

@edrevo edrevo commented Dec 21, 2025

This PR allows the reusable-containers feature to reuse stopped containers.

Motivation

I am trying to write integration tests with ClickHouse and Postgres, but I don't want to spin up one container per test. Moving the containers to a static OnceCell works, but unfortunately static variables are not dropped so the containers are not destroyed.

Integrating Ryuk as a solution to works, but the Ryuk container is not able to remove itself. Ryuk will successfully remove all test containers, and then shutdown. In order to avoid generating a Ryuk container per test run, I'd like to use reusable containers. Unfortunately, the current code fail as soon as Ryuk shuts down.

I am actually happy that Ryuk shuts down since that means it won't hog resources. What I want is for the reusable containers to be able to reuse my stopped Ryuk container, since that is the cleanest solution I have found for test container management on OnceCells.

@netlify
Copy link

netlify bot commented Dec 21, 2025

Deploy Preview for testcontainers-rust ready!

Name Link
🔨 Latest commit 23feb5d
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-rust/deploys/694915451ed0120008896455
😎 Deploy Preview https://deploy-preview-896--testcontainers-rust.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@DDtKey
Copy link
Contributor

DDtKey commented Dec 22, 2025

I believe it closes #893!

It's actually the desired behavior IMO, thanks for the contribution! 🚀

@DDtKey DDtKey changed the title Add support for reusable containers that have been stopped feat: support for reusable containers that have been stopped Dec 22, 2025
@DDtKey
Copy link
Contributor

DDtKey commented Dec 22, 2025

I am trying to write integration tests with ClickHouse and Postgres, but I don't want to spin up one container per test. Moving the containers to a static OnceCell works, but unfortunately static variables are not dropped so the containers are not destroyed

Integration with Ryuk and reusable-containers is the correct direction and we have plans for that for a while. And I really glad to accept PRs towards this direction.

However, as a workaround for your use-case you bc old try to use Weak + Arc combination, so parallel tests will reuse same container - see this example

@edrevo
Copy link
Contributor Author

edrevo commented Dec 22, 2025

Thanks for the quick review! I took a look at the CI failures and it looks due to rate limits on Docker Hub's side.

@DDtKey
Copy link
Contributor

DDtKey commented Dec 22, 2025

Don't worry about rate limits, we're aware of it and we will resolve it independently

@DDtKey
Copy link
Contributor

DDtKey commented Dec 22, 2025

Could you address clippy warning?

Generally LGTM!

@DDtKey DDtKey enabled auto-merge (squash) December 22, 2025 14:42
@DDtKey DDtKey disabled auto-merge December 22, 2025 15:05
@DDtKey DDtKey merged commit 79d110f into testcontainers:main Dec 22, 2025
17 of 18 checks passed
@DDtKey
Copy link
Contributor

DDtKey commented Dec 22, 2025

Thank you!

@edrevo edrevo deleted the support-stopped-containers branch December 22, 2025 18:00
@github-actions github-actions bot mentioned this pull request Dec 24, 2025
DDtKey added a commit that referenced this pull request Dec 24, 2025
## 🤖 New release

* `testcontainers`: 0.26.2 -> 0.26.3

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.26.3] - 2025-12-24

### Details
#### Features
- Support for reusable containers that have been stopped
([#896](#896))
- Support auto-detection of docker-compose client
([#898](#898))
- Allow customizations of host-config
([#899](#899))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Artem Medvedev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants