def _container_running(container_name): """ Check if a container is currently running or not. :param container_name: The container name or ID. :return: True if running, otherwise False. """ try: cdata = docker_client.inspect_container(container_name) except docker.errors.APIError as err: if err.response.status_code != 404: raise return False else: return cdata["State"]["Running"]
def get_container_info_or_exit(container_name): """ Get the full container info array from a partial ID or name. :param container_name: The partial ID or name of the container. :return: The container info array, or sys.exit if not found. """ try: info = docker_client.inspect_container(container_name) except docker.errors.APIError as e: if e.response.status_code == 404: print "Container %s was not found." % container_name else: print e.message sys.exit(1) return info