[FIX] error when killing container
This commit is contained in:
parent
9a212eeeb5
commit
7a2b19664d
|
|
@ -114,17 +114,28 @@ def exec_container(container, command):
|
||||||
|
|
||||||
def kill_container(container_name):
|
def kill_container(container_name):
|
||||||
client = get_docker_client()
|
client = get_docker_client()
|
||||||
|
|
||||||
|
try:
|
||||||
containers = client.containers.list(
|
containers = client.containers.list(
|
||||||
all=True,
|
all=True,
|
||||||
filters={"name": container_name},
|
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:
|
for container in containers:
|
||||||
if container.status != "exited":
|
if container.status != "exited":
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Stop container %s, based on image '%s'."
|
"Stop container %s, based on image '%s'."
|
||||||
% (container.name, ",".join(container.image.tags))
|
% (container.name, ",".join(container.image.tags))
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
container.stop()
|
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
|
# TODO, we should here filter by name
|
||||||
# but filters={"name": container_name}
|
# but filters={"name": container_name}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user