[FIX] error when killing container

This commit is contained in:
Rémy Taymans 2022-11-29 11:26:31 +01:00
parent 9a212eeeb5
commit 7a2b19664d

View File

@ -114,17 +114,28 @@ def exec_container(container, command):
def kill_container(container_name):
client = get_docker_client()
try:
containers = client.containers.list(
all=True,
filters={"name": container_name},
)
except docker.errors.NotFound as err:
logger.debug(f"Cannot kill container {container_name}: " + str(err))
containers = []
for container in containers:
if container.status != "exited":
logger.debug(
"Stop container %s, based on image '%s'."
% (container.name, ",".join(container.image.tags))
)
try:
container.stop()
except docker.errors.NotFound as err:
logger.debug(
f"Cannot kill container {container.name}: " + str(err)
)
# TODO, we should here filter by name
# but filters={"name": container_name}