From 0c60eebc1ed2321045a3ce234ad09fb532c022b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Wed, 16 Oct 2024 08:41:53 +0200 Subject: [PATCH] Purge exited container --- docky/cmd/run_open.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docky/cmd/run_open.py b/docky/cmd/run_open.py index 2ebf78e..b4e92b5 100644 --- a/docky/cmd/run_open.py +++ b/docky/cmd/run_open.py @@ -50,9 +50,15 @@ class DockyRun(DockyExec): """Start services and enter in your dev container""" def _check_running(self): - if docker.compose.ps(services=[self.service], all=True): - raise_error("This container is already running, kill it or " - "use open to go inside") + for service in docker.compose.ps(services=[self.service], all=True): + if service.state.status == "exited": + # In case that you have used "docker compose run" without the + # option "--rm" you can have exited container + # we purge them here as they are useless + service.remove() + else: + raise_error("This container is already running, kill it or " + "use open to go inside") def _main(self, *optionnal_command_line): super()._main(*optionnal_command_line)