You're overselling the "true cost" of maritime shipping - it's far and away the most efficient form of freight we have. Ocean freight has carbon emissions of 7g of CO2 per tonne-kilometre. Road freight by comparison has emissions of 137 gCO2/tkm - nearly 20 times the ocean emissions.
So, you would need to ship something 2000km before it has equivalent emissions to a 100km trip by road. So yea you're right that it'd be silly to ship something around the world rather than drive it 100km - but that's a a rather small distance. For a real-world example, you would produces less carbon shipping something from Shenzhen in China to San Francisco (11,078 km) than you would produce shipping it from San Francisco to Los Angeles by truck (616km by road).
No country has the density of population and the natural resources to have every conceivable industry within a 100 miles of every conceivable destination - eventually some goods are going to have to travel a longer distance, and once you get more than a couple of hundred kilometres away by road it genuinely becomes more efficient to move it across thousands of kilometres of ocean.