Why do bubbles initially stick to the side or the bottom of a glass while boiling?
The bubbles are already on the surface, they are just too small to see with the naked eye.
Wetting a surface, even at room temperature, results in tiny gas/vapor bubbles at defect sites due to surface tension. For example, surface tension prevents water from seeping into tiny crevices (on the order of microns).
These tiny gas pockets expand when heated, and eventually you can see them. They were on the surface the entire time, they just expanded. They stay on the surface because surface tension pulls down and balances the upward buoyant force.
If you keep adding more energy, however, the gas in the bubble will expand. Eventually the bubble will eject from the surface because the surface tension scales inversely with bubble radius, so the force holding it back decreases. Furthermore, as the bubble increases in volume at the surface, it gains an appreciable buoyant force that overcomes surface tension. At this point, the bubble rises.
You can actually superheat water above the boiling point if you have a surface that has small enough defects, since this makes it more difficult for gas bubbles to be trapped when the surface is wetted.
Anyways, the bubbles seem to stick to the sides of the container because they were always there to begin with, thanks to surface tension. You only see them when higher temperatures cause the gas inside them to expand.
It is expensive, in energy terms to, make a surface like the surface of a bubble.
By sticking to the walls or bottom of a container some of the surface is free, so it is energeticly favorable to stay partly attached until enough gas forms that the ratio of surface area to volume of gas reaches some limit (which depends on surface tension and the nature of the liquid and surface)