Other way around in locomotives. The fire goes through the tubes, the water surrounds them. The large number of tubes gives a really large surface area over which the fire's heat can be transferred to the water - it's a form of heat exchanger. The last energy of the exhaust steam from the cylinders is sent up the exhaust to create a forced draught that drags the fire through the tubes.
Later industrial and marine boilers turned this inside out and sent the water through tubes in the fire like you describe. This can be more efficient (because it's easier to hold high pressure in water tubes than a loco boiler) but only a few locos tried it and it didn't deliver much benefit there - seems to have been hard to make work well in loco format.
Trains need higher volume + they also have less space for the firebox/men to load them. In a boat you also don't have a water storage challenge. In a train you can store the water in same place as boiler - big win.
Still. The train sometimes stopping mid trip to build up steam was a thing.
Not sure if you are only asking about very old steam ships. More modern designs, as used by various naval forces as well as commercial operators, still use steam to convert thermal energy to mechanical energy. This is true whether they burn crude oil or even have nuclear reactors.
They have methods to "make water" by using some of their energy to run some kind of desalination plant. Traditionally, this was a distillation process. Newer ships might have reverse osmosis systems. I don't know which are preferred in military applications. Reverse osmosis is more energy efficient, but I can imagine that distillation may have more reliability under adverse conditions. I could imagine having both for efficiency with fault tolerance...
They would still also have a reservoir to store water for later use. That way, all the available thermal power can be directed towards locomotion when necessary. They can make water periodically, when power demands allow it and in a manner that would be most efficient for the equipment.
The desalination may not be perfect either. As I understand it, multiple US Navy ships inadvertently exposed their crews to Agent Orange during the Vietnam war through this process. They were not directly exposed to the chemical like victims on the land. Instead, the run-off from land went into river deltas and contaminated water was drawn in by nearby ships. The chemicals made it through the desalination process and into drinking water supplies.
Ships needed a source of pure water for the engines. In fact the boiler feed water system usually had the highest priority for use of pure water ahead of drinking water.