How did the alliance system cause world war 1?

If country A attacks country B, then A's allies also attack country B, and B's allies all come to the defense of B.