'Start a registry in a container.
The registry will be stopped and destroyed when the currently running
test finishes.
:return: A ``Registry`` describing the registry which was started.'

def run_registry(self):

    registry_name = random_name(self)
    registry_starting = self.start_container(unit_name=registry_name, image_name='registry:2', ports=[PortMap(internal_port=5000, external_port=0)], retry_on_port_collision=True)
    def extract_listening_port(client):
        listing = client.list()
        def listed(apps):
            [app] = [app for app in apps if (app.name == registry_name)]
            return next(iter(app.ports)).external_port
        listing.addCallback(listed)
        return listing
    registry_starting.addCallback(extract_listening_port)
    def wait_for_listening(external_port):
        registry = Registry(name=registry_name, port=external_port)
        registry_listening = self.request_until_response(registry.port)
        registry_listening.addCallback((lambda ignored: registry))
        return registry_listening
    registry_starting.addCallback(wait_for_listening)
    return registry_starting
