It really depends. Usually there are 2 captains assigned per ship with a couple of relief captains who fill gaps between breaks or would step in if the captain needed to leave for some reason (illness, family emergency, etc.)
But it's rare to be assigned to one for life - they can be moved from one ship as their primary to another depending on the needs of the line.