Your shoes get electrons from the carpet and get negatively charged. The electrons spread upward until your whole body has a negative charge in it. The negative charge in your hand pushes back electrons on the doorknob. The front of the doorknob gets a strong positive charge. Electrons jump from your hand to the doorknob.
You feel this electron jump as a doorknob shock.
Hope it helps!