listContainers method
The containers with all of the labels (name=value, or just
name); all includes the stopped ones.
Implementation
Future<List<DockerContainerSummary>> listContainers({
List<String> labels = const [],
bool all = false,
}) async {
final response = await _send(
'GET',
'/containers/json',
query: {
'all': '$all',
if (labels.isNotEmpty) 'filters': jsonEncode({'label': labels}),
},
);
final body = jsonDecode(await utf8.decodeStream(response));
return [
for (final item in (body as List<Object?>).cast<Map<String, Object?>>())
DockerContainerSummary(
id: '${item['Id']}',
image: '${item['Image']}',
state: '${item['State']}',
labels: {
for (final e
in ((item['Labels'] as Map<String, Object?>?) ?? const {})
.entries)
e.key: '${e.value}',
},
),
];
}