Though the exact roots of the tradition of calling a ship a "she" are lost to history, theories range from the practice of crafting female figureheads for a ship's prow to the dependent relationship that sailors had with their vessels. There are a number of other potential explanations as well.
The early term for a ship, specifically in Latin, was the word "navis," which was a feminine term which translates as "ship." By extension, when referring to a sea-going vessel, crew and captains came to use feminine pronouns when referencing the ship directly. So, rather than a gender neutral pronoun like "it," the ship became "she." This translated later into English as a simple tradition, though potentially because English was once also known for having a number of gender specific nouns for objects.
In truth, the real reason behind various vehicles being referred to as female may never be fully understood. It could simply be a way that predominantly male seafarers came to express their affection for the object that sustained them while in dangerous situations and helped to provide food for their families when coastal fishing became a major part of their lives. Regardless of the origin, the tradition is engraved in human culture all around the world and isn't likely to fade in the near future.