From the dictionary, it looks like it's some kind of ritual one does for luck, but I still cannot figure out when one would really knock on wood.
Knocking on wood used to be a way of warding off suspected impending bad luck, and now it's used as a tongue-in-cheek sort of phrase for when someone has had a lot of good luck, meaning that the person should be careful to avoid the bad luck which may follow. The Phrase Finder says:
This phrase is used by people who rap their knuckles on a piece of wood hoping to stave off bad luck. In the UK, the phrase 'touch wood' is used - often jokingly by tapping one's head. The phrases are sometimes spoken when a person is already experiencing some good fortune and hope that it will continue - for example "I've been winning on every race - touch wood".
The derivation may be the association that wood and trees have with good spirits in mythology, or with the Christian cross. It used to be considered good luck to tap trees to let the wood spirits within know you were there. Traditions of this sort still persist in Ireland. See also - the darling buds of May.
The British version of the phrase - 'touch wood', predates the American 'knock on wood' and was itself preceded by a Latin version - 'absit omen', meaning 'far be that omen from us'. This dates from at least the early 17th century, when it is quoted by John Heywood in his collections of proverbs. It isn't clear when 'touch wood' began to be used as a token of good fortune but it must have been by 1850, when the academic correspondence magazine Notes and Queries published this:
There probably is some old English expression for averting evil, but it does not come to mind; "I touch wood," "Bar omen," "Bar ill-luck," seem clumsy.
'Knock on wood' is known from the early 20th century; for example, The Syracuse Herald, February 1905:
Neglecting to knock on wood may have been responsible for the weather's unseemly behaviour today.
It basically means, "I know I might jinx myself". It reflects the awareness that what I say might be "famous last words". Some have considered it a way of "breaking the fourth wall". Great for describing sports predictions. To "jinx" refers to the power that spoken words have of counteracting the very thing they predict.
How to knock on wood:
Goofus: When the Rangers sweep the Canadiens, I'm going to take a week off work to watch the finals!
Uh oh! Goofus here is taking for granted the fact that the Rangers will sweep the Canadiens! But he is not protected from, either (1) the gods who hate hubris, (2) that life is but a stage, and has a penchant for dramatic irony, or (3) the magical power of spoken predictions to influence the world! He is in danger, in short, of being jinxed!
Gallant: When the Rangers sweep the Canadiens -- knock on wood -- I'm going to take a week off work to watch the finals!
See how, by knocking on wood and aknowledging those mysterious powers above, Gallant has not only insulated himself from those magical forces, but also the embarassing possibility of his freinds later bringing up this statement in his face! Huzzah!