Skip to content

Commit

Permalink
Merge pull request #435 from milanbalazs/main
Browse files Browse the repository at this point in the history
Remove the container in case of detach mode
  • Loading branch information
openshift-merge-bot[bot] authored Oct 7, 2024
2 parents 0863df6 + c8fa31a commit 8335410
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions podman/domain/containers_run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Mixin to provide Container run() method."""

import logging
import threading
from contextlib import suppress
from typing import Generator, Iterator, List, Union

Expand Down Expand Up @@ -67,7 +68,19 @@ def run(
container.start()
container.reload()

def remove_container(container_object: Container) -> None:
"""
Wait the container to finish and remove it.
Args:
container_object: Container object
"""
container_object.wait() # Wait for the container to finish
container_object.remove() # Remove the container

if kwargs.get("detach", False):
if remove:
# Start a background thread to remove the container after finishing
threading.Thread(target=remove_container, args=(container,)).start()
return container

with suppress(KeyError):
Expand Down

0 comments on commit 8335410

Please sign in to comment.