Refusing to sacrifice his principles, the captain knows he can't remain in Austria and serve in the navy under the German occupation. The film ends with the von Trapp family traipsing through the Alps to Switzerland, secretly escaping from Herr Zeller and his Nazi minions.
The scene also refers back to climbing those metaphorical mountains that the Reverend Mother sang about; it completes the story's circle. It's an anxious scene, but full of hope and courage. It leaves the family's fate up in the air, but we have faith in the captain to lead everyone to safety. Plus, we know that the real von Trapps got out of Austria.
Then again, maybe we didn't know that when we were seven.
Especially since that's not really how the von Trapps got out of Austria (they actually took a train to Italy and told people where they were going), many critics saw the ending as overly sentimental and melodramatic.