INNER CODE UNIT · Python
get_container_by_image
ahembree/ansible-hms-docker · roles/hmsdocker/files/scripts/traefik_cert_convert.py:181
def get_container_by_image(image: str):
"""Gets the Container object based on the image name
Args:
image (``str``): The image used to start the container
Returns:
``str`` or ``list``: The Container object or list of Container objects
"""
container_list = docker_client.containers.list(filters={
'ancestor': image
})
if len(container_list) == 1:
return container_list[0]
else:
logging.warning(f'Got more than one container for image {image}, found: {len(container_list)}')
return container_list