-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Add support for reusing stopped containers #849
Add support for reusing stopped containers #849
Conversation
✅ Deploy Preview for testcontainers-node ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Nice, thanks for raising. Could you please add a test for the new functionality? |
Sure thing @cristianrgreco! Added a new test for reusing stopped (but not removed) containers 👍🏻 Another thing I thought about which I'm unsure if should be handled explicitly or not, but the |
Also, coming from using TestContainers in C# I was a bit surprised to find that stopping the container by default also auto-removes it. Maybe |
49e1f99
to
3cdb2bd
Compare
@cbrevik You can specify not to remove the container when stopping it with
This is a good point. It is probably best not to try to restart the old container if it is dead/removing. If we add this filter, then testcontainers will start a new container as expected. In fact not adding this filter could result in breaking changes. Would you be able to update the PR with a test for this? |
Yeah I've used the that way to disable removing it with
The reason I thought it might be better to just let it throw is because either way one would have to manually clean it up probably (for But either way I'll update with the filter for dead/removing + tests for that. 👍🏻 |
@cristianrgreco I've added a filter for |
packages/testcontainers/src/generic-container/generic-container-reuse.test.ts
Outdated
Show resolved
Hide resolved
afec496
to
0bc18b8
Compare
Looks like Podman doesn't support the
We can either add a Podman specific implementation, or just forget about the filters |
@cristianrgreco how about just removing |
Sure |
Closes #783
I looked into this a bit and as suggested removing the status-filter in
fetchByLabel
will make it find the exited container. And then I had to check if it is running or not, and start it if not.But I hit on a problem when using
@testcontainers/postgresql
that it could not find bound ports on an exited container that is being restarted:The bound ports are created from a an inspection result when trying to reuse the container.
And the ports in the inspection results are mapped from the
NetworkSettings.Ports
section when inspecting the container.The underlying issue here though is that
NetworkSettings
seems to be reflecting what a running container has as current network settings. Which is empty values when doingdocker inspect
on an exited container:Compared to a running container:
So basically I had to inspect the container again after re-starting it to get the correct bound ports and their IPs.