def get_exposed_hostports(container_id): """ Get the host ports we exposed when we ran this container. :param container_id: str: the id or name of the running container :return list """ # Since we ran the container, we can guarantee that # one host port and one or more container ports are exposed. # Example of port_map: # # {'4848/tcp': None, # '8080/tcp': [{'HostPort': '8080', 'HostIp': '0.0.0.0'}], # '8181/tcp': None} try: port_map = _get_network_settings(container_id)[PORTS_KEY] or {} return utils.flatten([[p[HOST_PORT_KEY] for p in ports] for ports in six.itervalues(port_map) if ports]) except CommandError: # Not running return []