Fix discovery when some containers have no forwarded ports

In the new API, docker can return nil in the JSON to indicate a container
has no ports forwarded. This notably happens when you're using the 'docker build'
command, and breaks synapse's discovery for the duration.

If you have a long running container with no ports forwarded, then
it's just always broken.

This fixes that bug and breaks out rewrite_container_ports into it's own
method as it's complex enough to justify it. Tests are added for the
3 (old/new/nil) cases that this method deals with