def extract_external_port(client, container_identifier, internal_port):
 container_details = client.inspect_container(container_identifier)
 network_settings = container_details[u'NetworkSettings']
 ports = network_settings[u'Ports']
 details = ports[u'{}/tcp'.format(internal_port)]
 host_port = int(details[0][u'HostPort'])
 Message.new(message_type=u'acceptance:extract_external_port', host_port=host_port).write()
 return host_port

def extract_external_port ( client , container_identifier , internal_port ) : container_details = client . inspect_container ( container_identifier ) network_settings = container_details [ u'NetworkSettings' ] ports = network_settings [ u'Ports' ] details = ports [ u'{}/tcp' . format ( internal_port ) ] host_port = int ( details [ 0 ] [ u'HostPort' ] ) Message . new ( message_type = u'acceptance:extract_external_port' , host_port = host_port ) . write ( ) return host_port
inspect a running container for the external port number on which a particular internal port is exposed .