Fix listing containers during removal of containers

Removing a container can take some time to be performed. Listing
containers when a container is currently being removed may cause errors.
Because listing container and filtering them by name requires to fetch
data from the container that is currently being removed.
This commit is contained in:
Rémy Taymans 2023-11-09 16:27:29 +01:00
parent a0307847b9
commit a3a8af9a70
2 changed files with 4 additions and 1 deletions

View File

@ -130,6 +130,7 @@ def kill_container(container_name):
containers = client.containers.list(
all=True,
filters={"name": container_name},
ignore_removed=True,
)
except docker.errors.NotFound as err:
logger.debug(f"Cannot kill container {container_name}: " + str(err))

View File

@ -21,7 +21,9 @@ def get_postgres_container(ctx):
# Check if container exists
containers = client.containers.list(
all=True, filters={"name": container_name}
all=True,
filters={"name": container_name},
ignore_removed=True,
)
if containers:
container = containers[0]