I'm coding tests with python. I want to make a method that outputs the status of a container (running/exited).
import docker
class Container:
def __init__(self, name, image, *, command=[], links={}):
self._docker = docker.DockerClient(base_url='unix://var/run/docker.sock')
def get_status(self):
inspection = self._docker.api.inspect_container(self.id)
return inspection['State']['Status']
this method (get_status) works when container is running but fails when container is stopped, with this error message:
E docker.errors.NotFound: 404 Client Error: Not Found ("No such container: 2457e5a283e5cb4add4fdb36pb465437b21bb21f768be405fe40615e25442d6e
"docker inspect" cli command works on the instance when it is stopped, but I need to do it through python
any ideas?