"The ship's anchor in “O Captain! My Captain!” is a symbol for the end of Civil War and Lincoln's death. While the voyage symbolizes the Civil War, it may also symbolize Lincoln's life. When the speaker says that the anchored ship is safe and sound, Whitman refers to the country being out of war and in a state of peace."
-https://education.seattlepi.com/examples-symbolism-o-captain-captain-6107.html