You’re confusing the age of sail, medieval times, and the ancient Mediterranean.
Ships in ancient Greece didn’t go very far from land, and often didn’t have facilities to cook or sleep on board, so the crews would beach the ship each night and cook and sleep on shore.
Medieval ships certainly did go far from land- remember, the Vikings crossed the Atlantic. I don’t know what they ate while doing so, though. And people may have reached the Azores in the 14th century.
Once you get to the age of sail (16th century) with ships regularly sailing across oceans, we know exactly what they ate, and ships definitely did have a galley. The meat was carried salted in casks (though they ate fresh when available and often carried livestock), and was boiled by the ship’s cook. The chief qualification for being a ship’s cook was to be a disabled navy veteran.
Here’s a very interesting article about it…