aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2019-02-25 16:23:15 -0500
committerBryn M. Reeves <bmr@redhat.com>2019-03-20 14:47:44 +0000
commit785d72bcfa661d96ba2b20b425a3d6d52d51a1da (patch)
tree3b037ec33d68c7981a6b25cf0a753a91a13b436b
parent68c73563958c6ffdb21388b60895e8a63952478a (diff)
downloadsos-785d72bcfa661d96ba2b20b425a3d6d52d51a1da.tar.gz
[docker] Correct commands, collect volume info
Fixes the potential for 'docker logs' to be called against images and adds volume collection for docker like #1579 does for podman. Changes image inspections to use the image name, unless the name or tag is 'none' in which case the image ID is used. Resolves: #1580 Signed-off-by: Jake Hunsaker <jhunsake@redhat.com> Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/plugins/docker.py43
1 files changed, 28 insertions, 15 deletions
diff --git a/sos/plugins/docker.py b/sos/plugins/docker.py
index 3cce15ed..d8c854f9 100644
--- a/sos/plugins/docker.py
+++ b/sos/plugins/docker.py
@@ -72,21 +72,34 @@ class Docker(Plugin):
if self.get_option('all'):
ps_cmd = "%s -a" % ps_cmd
- img_cmd = 'docker images -q'
- insp = set()
-
- for icmd in [ps_cmd, img_cmd]:
- result = self.get_command_output(icmd)
- if result['status'] == 0:
- for con in result['output'].splitlines():
- insp.add(con)
-
- insp = list(insp)
- if insp:
- for container in insp:
- self.add_cmd_output("docker inspect %s" % container)
- if self.get_option('logs'):
- self.add_cmd_output("docker logs -t %s" % container)
+ fmt = '{{lower .Repository}}:{{lower .Tag}} {{lower .ID}}'
+ img_cmd = "docker images --format='%s'" % fmt
+ vol_cmd = 'docker volume ls -q'
+
+ containers = self._get_docker_list(ps_cmd)
+ images = self._get_docker_list(img_cmd)
+ volumes = self._get_docker_list(vol_cmd)
+
+ for container in containers:
+ self.add_cmd_output("docker inspect %s" % container)
+ if self.get_option('logs'):
+ self.add_cmd_output("docker logs -t %s" % container)
+
+ for img in images:
+ name, img_id = img.strip().split()
+ insp = name if 'none' not in name else img_id
+ self.add_cmd_output("docker inspect %s" % insp)
+
+ for vol in volumes:
+ self.add_cmd_output("docker volume inspect %s" % vol)
+
+ def _get_docker_list(self, cmd):
+ ret = []
+ result = self.get_command_output(cmd)
+ if result['status'] == 0:
+ for ent in result['output'].splitlines():
+ ret.append(ent)
+ return ret
def postproc(self):
# Attempts to match key=value pairs inside container inspect output