Return the correct context-path in-container [IMMUTANT-477]

This also includes cleanup of similar util fns, and removes duplication
of code for port lookup.