On first impression Shrek is pretty scary. Donkey has good survival instincts (seeing as he tried to keep his mouth shut when the old crone tried to sell him, and after the fairy dust mishap he ran away as fast as he could). So why he didn't keep running after he bumped into Shrek, letting the knights and the ogre deal with each other?
Also, a few minutes later, Shrek tries to scare Donkey away by roaring, but Donkey is not impressed. How did Donkey know that Shrek was harmless? True, Shrek did not kill the leader of the knights, but that could have meant that the monster just ate and he was full and lazy. Why did Donkey decide to stay, risking the wrath of an annoyed ogre, and didn't even keep a safe distance from him at first?
The answer of @RoyalCanadianBandit reminded me that in similar circumstances -- encountering a female ogre at night -- he assumed the worst: that the ogre, as it is in her nature, ate the princess:
DONKEY
Shrek! Shrek! Shrek!FIONA
No, it's okay. It's okay.DONKEY
What did you do with the princess?FIONA
Donkey, I'm the princess. [...]It's me, in this body.DONKEY
Oh, my God! You ate the princess. (to her stomach) Can you hear me?
He is mostly used as the comedy mule donkey so I am not sure, but it seems he was genuinely scared of Fiona in her ogre form. So why wasn't he scared of Shrek?