From 53c406f7e0f916a35c4b2e73d252e68ece63670c Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 23 Jul 2018 21:37:22 +0000 Subject: [PATCH] Check container is running before trying to open its namespace Otherwise we get pointless errors. --- probe/docker/container.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/probe/docker/container.go b/probe/docker/container.go index aa6377291..6c4dd3f6c 100644 --- a/probe/docker/container.go +++ b/probe/docker/container.go @@ -277,15 +277,17 @@ func (c *container) NetworkInfo(localAddrs []net.IP) report.Sets { ips = append(ips, c.container.NetworkSettings.IPAddress) } - // Fetch IP addresses from the container's namespace - cidrs, err := namespaceIPAddresses(c.container.State.Pid) - if err != nil { - log.Debugf("container %s: failed to get addresses: %s", c.container.ID, err) - } - for _, cidr := range cidrs { - // This address can duplicate an address fetched from Docker earlier, - // but we eventually turn the lists into sets which will remove duplicates. - ips = append(ips, cidr.IP.String()) + if c.container.State.Running && c.container.State.Pid != 0 { + // Fetch IP addresses from the container's namespace + cidrs, err := namespaceIPAddresses(c.container.State.Pid) + if err != nil { + log.Debugf("container %s: failed to get addresses: %s", c.container.ID, err) + } + for _, cidr := range cidrs { + // This address can duplicate an address fetched from Docker earlier, + // but we eventually turn the lists into sets which will remove duplicates. + ips = append(ips, cidr.IP.String()) + } } // For now, for the proof-of-concept, we just add networks as a set of