East and Gulf Coast port operators late Wednesday struck an agreement with a dockworkers union, resolving a labor dispute that had threatened to halt shipments for a second time in three months.