Part of the problem is dock unions limit working hours, unlike other countries that go 24/7, so deliveries pile up. Then, many containers were stacked up in various US ports and sold off for low rent housing, helping create the current shortage of containers.
Years ago, pre-9/11, I found out that longshoremen with high school-level education were able to draw six figure salaries that anywhere else in America would be 8-10/hour due to the strength of their unions. They were also able to force shipping companies to use manual-intensive procedures and prevent adoption of time-saving modernization like using barcodes, all in the name of preventing anyone from taking union jobs.
After 9/11, the unions claimed all of those antiquated procedures were needed for Homeland security.
The military could clear out all of those backlogs across all American ports in a few weeks, or at least the pre-Biden military could. But doing so would expose the absurdity of the longshoremen and those six figure incomes also come with powerful political protection that overlaps with teamsters and other union labor who are similarly protected. Right now we're seeing a perfect storm of protectionism, graft, and over reliance on cheap imports that ultimately hurts American industry. I don't see it getting better for a very long time at the pace we're going.