From d9e5a62458ea04682e3c4546b781a46018e2ca1c Mon Sep 17 00:00:00 2001
From: Einar Forselv <eforselv@gmail.com>
Date: Sun, 8 Dec 2019 00:26:02 +0100
Subject: [PATCH] List all containers including non-running ones

---
 src/restic_compose_backup/containers.py | 8 ++++++--
 src/restic_compose_backup/utils.py      | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/restic_compose_backup/containers.py b/src/restic_compose_backup/containers.py
index 4b3c9ab..372e6e4 100644
--- a/src/restic_compose_backup/containers.py
+++ b/src/restic_compose_backup/containers.py
@@ -142,7 +142,7 @@ class Container:
 
     @property
     def is_running(self) -> bool:
-        """Is the container running?"""
+        """bool: Is the container running?"""
         return self._state.get('Running', False)
 
     @property
@@ -326,10 +326,14 @@ class RunningContainers:
         if not self.this_container:
             raise ValueError("Cannot find metadata for backup container")
 
-        # Gather all containers in the current compose setup
+        # Gather all running containers in the current compose setup
         for container_data in all_containers:
             container = Container(container_data)
 
+            # We only care about running containers
+            if not container.is_running:
+                continue
+
             # Detect running backup process container
             if container.is_backup_process_container:
                 self.backup_process_container = container
diff --git a/src/restic_compose_backup/utils.py b/src/restic_compose_backup/utils.py
index 9087e70..aef8d99 100644
--- a/src/restic_compose_backup/utils.py
+++ b/src/restic_compose_backup/utils.py
@@ -16,7 +16,7 @@ def list_containers():
     """
     config = Config()
     client = docker.DockerClient(base_url=config.docker_base_url)
-    all_containers = client.containers.list()
+    all_containers = client.containers.list(all=True)
     client.close()
     return [c.attrs for c in all_containers]