Get a cargo rack and use good bungee cords.

That’s the standard solution for a reason. You need a solid mounting point (rear rack, pannier rack, or tail) and a method that won’t let the cooler shift.

For motorcycles, a dedicated cooler