src/toil_lib/__init__.py
def current_docker_container_id():
    """
    Returns a string that represents the container ID of the current Docker container. If this
    function is invoked outside of a container a NotInsideContainerError is raised.

    >>> import subprocess
    >>> import sys
    >>> a = subprocess.check_output(['docker', 'run', '-v',
    ...                              sys.modules[__name__].__file__ + ':/foo.py',
    ...                              'python:2.7.12','python', '-c',
    ...                              'from foo import current_docker_container_id;\\
    ...                               print current_docker_container_id()'])
    int call will fail if a is not a valid hex string
    >>> int(a, 16) > 0
    True
    """
    try:
        with open('/proc/1/cgroup', 'r') as readable:
            raw = readable.read()
        ids = set(re.compile('[0-9a-f]{12,}').findall(raw))
        assert len(ids) == 1
        return ids.pop()
    except:
        logging.exception('Failed to obtain current container ID')
        raise NotInsideContainerError()
def current_docker_container_id():
    try:
        with open('/proc/1/cgroup', 'r') as readable:
            raw = readable.read()
        ids = set(re.compile('[0-9a-f]{12,}').findall(raw))
        assert len(ids) == 1
        return ids.pop()
    except:
        logging.exception('Failed to obtain current container ID')
        raise NotInsideContainerError()
def current_docker_container_id ( ) : try : with open ( '/proc/1/cgroup' , 'r' ) as readable : raw = readable . read ( ) ids = set ( re . compile ( '[0-9a-f]{12,}' ) . findall ( raw ) ) assert len ( ids ) == 1 return ids . pop ( ) except : logging . exception ( 'Failed to obtain current container ID' ) raise NotInsideContainerError ( )
Returns a string that represents the container ID of the current Docker container. If this
    function is invoked outside of a container a NotInsideContainerError is raised.

    >>> import subprocess
    >>> import sys
    >>> a = subprocess.check_output(['docker', 'run', '-v',
    ...                              sys.modules[__name__].__file__ + ':/foo.py',
    ...                              'python:2.7.12','python', '-c',
    ...                              'from foo import current_docker_container_id;\\
    ...                               print current_docker_container_id()'])
    int call will fail if a is not a valid hex string
    >>> int(a, 16) > 0
    True
Returns a string that represents the container ID of the current Docker container . If this function is invoked outside of a container a NotInsideContainerError is raised .