Shaking the container makes harmless little particles at the bottom of the container mix throughout the soda. Edges and rough spots on those little bits are places where bubbles can form. So the carbon dioxide gas that was dissolved into the soda to give it fizz comes out of the soda fast, as lots of tiny bubbles.
Art by: John Haslam