I'm no expert, but my understanding is this. Before there were donkey engines (shipboard engines to which lines would be fastened to do all manner of work) there were donkey winches (shipboard winches to which lines would be fastened to do all manner of work.) Donkey Riding was one of the chanties used for working a donkey winch.
I saw a picture of a donkey winch once. As I recall, it was rather like a seesaw with a long handle at each end. Four sailors would hold onto each handle, and they would haul the handles up and down to work the winch.