You realize that all of the railways already offer this exact service and have been doing so for a long time, right? There is a reason why CN and CP have purchased lines deep into the US in the past 30 years, and why the ports on the West Coast are considerably busier than those on the East.
I know several of the west coast ports are at, or close to capacity.
One reason cited, is the inability to get railway cars moved out fast enough (backlog) precluding further offloading of ships (there are other issues as well, of course)
We also know that CN and other railways have capacity constraints as well, bottlenecks, though they run far fewer trains than they once did, train length with limited siding/passing tracks constrains capacity.
Premamble done........here's the question; if our railways wanted to or 'had to' take on 20% of Panama's traffic could they? Assuming upgrades were required (additional track, more/longer sidings, more yard capacity), how long would they need to be ready?