From 785d72bcfa661d96ba2b20b425a3d6d52d51a1da Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Mon, 25 Feb 2019 16:23:15 -0500 Subject: [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 Signed-off-by: Bryn M. Reeves --- sos/plugins/docker.py | 43 ++++++++++++++++++++++++++++--------------- 1 file 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 -- cgit