There is a familiar metaphor that is germane to this elegiac poem; namely, the ship of state. The lines 19-20
The ship is anchor’d safe and sound, its voyage closed and done;
From fearful trip, the victor ship, comes in with object won;
The Civil War has been won by the North, arresting the secession of the Confederate States--the Union is preserved after "fearful" battle and great loss of American lives. But, it also has been won, it seems, at the price of losing the captain of this ship of state: President Abraham Lincoln has been assassinated. Now, with the captain slain, the president murdered, the ship of state is not safe, though it be in harbor. Furthermore, the poet Whitman, who felt strongly about Lincoln, is himself lugubrious:
But I, with mournful tread,
Walk the deck my Captain lies,
Fallen cold and dead.
With the captain of the victorious ship dead, there now is a sense of futility in the poem that conjures another familiar expression, "At what price glory?"
In the poem "O Captain! My captain!" by Walt Whitman, the ship does symbolize the United States of America. More particularly, the ship represents the union army at the end of the Civil War. The victory at the end of the battle in the poem represents the victory of the union army over the Confederacy after the war in 1865. The ship is sailing into port and the citizens on land have fireworks going and there's a big party to celebrate the end of the battle (or war). Just as the ship represents the union army, the captain represents Abraham Lincoln who dies too soon to see the full rewards of victory and peace. The ship is a vessel like the United States is a vessel that carries it's people and leader together through war and peace.