(idiomatic) In an adverse situation, when one lacks good alternatives, it is appropriate to avail oneself of any possible refuge, aid, or helpful course of action.
1804 Aug. 4, "Levity: Bob Rousem's Epistle to Bonypart," The Port Folio, vol. 4, no. 31, p. 246 (Google books):
I'll give you the journal, my boy. . . . eight A.M. Bonypart running away; nine A.M. Bonypart on board; ten A.M. Bonypart sinking; eleven A.M. Bonypart in Davy's Locker; Meridian Bonypart in the north corner of _____ , where it burns and freezes at the same time: but you know any port in a storm, Bony, so there I'll leave ye.
After finding both stairwells untenable at the roof, the Captain and the rookie take the window‐washing scaffold—any port in a storm—down the side of the building to the fire floor.
2008 December 28,Jon Henderson,“Kinnear: A man you can swear by”, inThe Observer:
He wasn't the most popular appointment, but I think the phrase ‘any port in a storm’ came to mind when we were getting turned down by everyone.
Usage notes
This expression is usually used as if it were a complete sentence, serving as an ellipsis of "Go to any port in a storm", "Any port will do in a storm", or any similar sentence.