Get the ID of the container the application is currently running in,
    otherwise return `None` if not running in a container.

    This is a best-effort guess, based on cgroups.

    :param read_from: the cgroups file to read from (default: `/proc/self/cgroup`)

def get_current_container_id(read_from='/proc/self/cgroup'):
    """
    Get the ID of the container the application is currently running in,
    otherwise return `None` if not running in a container.

    This is a best-effort guess, based on cgroups.

    :param read_from: the cgroups file to read from (default: `/proc/self/cgroup`)
    """

    if not os.path.exists(read_from):
        return

    with open(read_from, 'r') as cgroup:
        for line in cgroup:
            if re.match('.*/[0-9a-f]{64}$', line.strip()):
                return re.sub('.*/([0-9a-f]{64})$', '\\1', line.strip())