Allow option to keep the containers alive
See original GitHub issueIt would be nice to keep the docker containers alive for speeding up the test runs. Now, in every test run containers are re-created and can’t keep them alive since this block
def __del__(self):
"""
Try to remove the container in all circumstances
"""
if self._container is not None:
try:
self.stop()
except: # noqa: E722
pass
removes containers when the instance variable is deleted (when the program terminates) and I cannot override it because this also runs without using with as
block.
I don’t want my Mysql container to be recreated everytime. I am running tests very frequently and I am waiting couple seconds everytime. Pretty annoying.
I can make a small PR if that makes sense?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:6
Top Results From Across the Web
Keep containers alive during daemon downtime
There are two ways to enable the live restore setting to keep containers alive when the daemon becomes unavailable. Only do one of...
Read more >Enabling live restore on docker isn't keeping the containers ...
The live restore option only works to restore containers if the daemon options, such as bridge IP addresses and graph driver, did not...
Read more >Keep containers alive during daemon downtime
Live restore supports keeping containers running across Docker daemon upgrades, though this is limited to patch releases and does not support minor or...
Read more >How To Keep Docker Container Running For Debugging
To keep the container running, you need a foreground process added to the Docker Entrypoint. In the official Nginx image, the Nginx foreground ......
Read more >podman-run
keep-groups is a special flag that tells Podman to keep the supplementary group access. Allows container to use the user's supplementary group access....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sounds like there is sufficiently broad interest in this feature. We could add a
remove: bool = True
keyword argument to the constructor and keep the container alive ifnot remove
. Note that a PR would now need to modify theatexit
registration once #208 is merged.@Can-Sahin, makes sense to want to keep the container alive to speed up tests. Having said that, I’m not sure how you’d be able to connect to the existing container after the reference to the instance variable has been discarded.
If you’re using pytest, you can use global fixtures to reuse the same container across all test runs within the same process. Reusing an existing container across different test runs/processes would require persisting information about the container across runs—container management should probably be outside the scope of this project.