podman-py icon indicating copy to clipboard operation
podman-py copied to clipboard

Container is not deleted if detach=True and remove=True are specified

Open landgraf opened this issue 1 year ago • 2 comments

remove: Delete container when the container's processes exit. Default: False.

>>> import podman
>>> podman.__version__
'5.0.0'
>>> c = client.containers.run("myimage", detach=True, remove=True, command="/bin/false")
>>> c.status
'exited'

26034e386c92  myimage                                            /bin/false            14 seconds ago     Exited (1) 14 seconds ago              interesting_williamson

landgraf avatar Jun 24 '24 13:06 landgraf

A note:

The following example won't reproduce the issue

from podman import PodmanClient

uri = "unix:///run/user/1000/podman/podman.sock"

with PodmanClient(base_url=uri) as client:
    c = client.containers.run("nginx", remove=True, command="/bin/false")

    print(c.status)

while

from podman import PodmanClient

uri = "unix:///run/user/1000/podman/podman.sock"

with PodmanClient(base_url=uri) as client:
    c = client.containers.run("nginx", deatch=True, remove=True, command="/bin/false")

    print(c.status)

will reproduce

inknos avatar Jul 29 '24 14:07 inknos

Ok, the problem is just that detach is called before remove. I can see how the options can live together, but since I would avoid delegating the removal to the user or threading/scheduling the removal.

Maybe @jwhonce might have something to add about the reasoning behind the code, or if there were some thoughts already on this detach/remove process.

inknos avatar Jul 30 '24 10:07 inknos