# Buggy code
def get_docker_io(self, container_id, all_stats):
    """Return the container IO usage using the Docker API (v1.0 or higher).

    Input: id is the full container id
    Output: a dict {'time_since_update': 3000, 'ior': 10, 'iow': 65}.
    with:
        time_since_update: number of seconds elapsed between the latest grab
        ior: Number of byte readed
        iow: Number of byte written
    """
    # Init the returned dict
    io_new = {}

    # Read the ior/iow stats (in bytes)
    try:
        iocounters = all_stats["blkio_stats"]
    except KeyError as e:
        # all_stats do not have io information
        logger.debug(
            "docker plugin - Cannot grab block IO usage for container {} ({})".format(
                container_id, e
            )
        )
        logger.debug(all_stats)
        # No fallback available...
        return io_new

    # Previous io interface stats are stored in the io_old variable
    if not hasattr(self, "iocounters_old"):
        # First call, we init the io_old var
        self.iocounters_old = {}
        try:
            self.iocounters_old[container_id] = iocounters
        except (IOError, UnboundLocalError):
            pass

    if container_id not in self.iocounters_old:
        try:
            self.iocounters_old[container_id] = iocounters
        except (IOError, UnboundLocalError):
            pass
    else:
        # By storing time data we enable IoR/s and IoW/s calculations in the
        # XML/RPC API, which would otherwise be overly difficult work
        # for users of the API
        try:
            # Read IOR and IOW value in the structure list of dict
            ior = [
                i for i in iocounters["io_service_bytes_recursive"] if i["op"] == "Read"
            ][0]["value"]
            iow = [
                i
                for i in iocounters["io_service_bytes_recursive"]
                if i["op"] == "Write"
            ][0]["value"]
            ior_old = [
                i
                for i in self.iocounters_old[container_id]["io_service_bytes_recursive"]
                if i["op"] == "Read"
            ][0]["value"]
            iow_old = [
                i
                for i in self.iocounters_old[container_id]["io_service_bytes_recursive"]
                if i["op"] == "Write"
            ][0]["value"]
        except (IndexError, KeyError, TypeError) as e:
            # all_stats do not have io information
            logger.debug(
                "docker plugin - Cannot grab block IO usage for container {} ({})".format(
                    container_id, e
                )
            )
        else:
            io_new["time_since_update"] = getTimeSinceLastUpdate(
                "docker_io_{}".format(container_id)
            )
            io_new["ior"] = ior - ior_old
            io_new["iow"] = iow - iow_old
            io_new["cumulative_ior"] = ior
            io_new["cumulative_iow"] = iow

            # Save stats to compute next bitrate
            self.iocounters_old[container_id] = iocounters

    # Return the stats
    return io_new


# Traceback (TypeError)
user@user-Virtual-Machine:~/Docker/docker-glances$ sudo docker ps --no-trunc
CONTAINER ID                                                       IMAGE               COMMAND                                                                              CREATED             STATUS                         PORTS               NAMES
d9e4106cf276936a39857ca52157780a2f25b619ae8defc58ab21cf19d4a6db2   mynetdata           "/bin/sh -c '/usr/sbin/netdata -D -s /host -u root  -c /tmp/netdata/netdata.conf'"   30 seconds ago      Restarting (1) 2 seconds ago                       netdata

user@user-Virtual-Machine:~/Docker/docker-glances$  sudo docker logs glances
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/bottle.py", line 862, in _handle
return route.call(**args)
File "/usr/lib/python3.6/site-packages/bottle.py", line 1740, in wrapper
rv = callback(*a, **ka)
File "/usr/lib/python3.6/site-packages/glances/outputs/glances_bottle.py", line 533, in _enable_cors
return fn(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/glances/outputs/glances_bottle.py", line 164, in _index
self.__update__()
File "/usr/lib/python3.6/site-packages/glances/outputs/glances_bottle.py", line 89, in __update__
self.stats.update()
File "/usr/lib/python3.6/site-packages/glances/stats.py", line 192, in update
self._plugins[p].update()
File "/usr/lib/python3.6/site-packages/glances/plugins/glances_plugin.py", line 884, in wrapper
ret = fct(self, *args, **kw)
File "/usr/lib/python3.6/site-packages/glances/plugins/glances_plugin.py", line 893, in wrapper
ret = fct(*args, **kw)
File "/usr/lib/python3.6/site-packages/glances/plugins/glances_docker.py", line 269, in update
container['io'] = self.get_docker_io(container['Id'], self.thread_list[container['Id']].stats)
File "/usr/lib/python3.6/site-packages/glances/plugins/glances_docker.py", line 453, in get_docker_io
ior = [i for i in iocounters['io_service_bytes_recursive'] if i['op'] == 'Read'][0]['value']
TypeError: 'NoneType' object is not iterable

# Fixed code
def get_docker_io(self, container_id, all_stats):
    """Return the container IO usage using the Docker API (v1.0 or higher).

    Input: id is the full container id
    Output: a dict {'time_since_update': 3000, 'ior': 10, 'iow': 65}.
    with:
        time_since_update: number of seconds elapsed between the latest grab
        ior: Number of byte readed
        iow: Number of byte written
    """
    # Init the returned dict
    io_new = {}

    # Read the ior/iow stats (in bytes)
    try:
        iocounters = all_stats["blkio_stats"]
    except KeyError as e:
        # all_stats do not have io information
        logger.debug(
            "docker plugin - Cannot grab block IO usage for container {} ({})".format(
                container_id, e
            )
        )
        logger.debug(all_stats)
        # No fallback available...
        return io_new

    # Previous io interface stats are stored in the io_old variable
    if not hasattr(self, "iocounters_old"):
        # First call, we init the io_old var
        self.iocounters_old = {}
        try:
            self.iocounters_old[container_id] = iocounters
        except (IOError, UnboundLocalError):
            pass

    if container_id not in self.iocounters_old:
        try:
            self.iocounters_old[container_id] = iocounters
        except (IOError, UnboundLocalError):
            pass
    else:
        # By storing time data we enable IoR/s and IoW/s calculations in the
        # XML/RPC API, which would otherwise be overly difficult work
        # for users of the API
        try:
            # Read IOR and IOW value in the structure list of dict
            ior = [
                i for i in iocounters["io_service_bytes_recursive"] if i["op"] == "Read"
            ][0]["value"]
            iow = [
                i
                for i in iocounters["io_service_bytes_recursive"]
                if i["op"] == "Write"
            ][0]["value"]
            ior_old = [
                i
                for i in self.iocounters_old[container_id]["io_service_bytes_recursive"]
                if i["op"] == "Read"
            ][0]["value"]
            iow_old = [
                i
                for i in self.iocounters_old[container_id]["io_service_bytes_recursive"]
                if i["op"] == "Write"
            ][0]["value"]
        except (TypeError, IndexError, KeyError) as e:
            # all_stats do not have io information
            logger.debug(
                "docker plugin - Cannot grab block IO usage for container {} ({})".format(
                    container_id, e
                )
            )
        else:
            io_new["time_since_update"] = getTimeSinceLastUpdate(
                "docker_io_{}".format(container_id)
            )
            io_new["ior"] = ior - ior_old
            io_new["iow"] = iow - iow_old
            io_new["cumulative_ior"] = ior
            io_new["cumulative_iow"] = iow

            # Save stats to compute next bitrate
            self.iocounters_old[container_id] = iocounters

    # Return the stats
    return io_new