Rainbows appear in seven colors because water droplets break sunlight into the seven colors of the spectrum. You get the same result when sunlight passes through a prism. The water droplets in the atmosphere act as prisms, though the traces of light are very complex.
When light meets a water droplet, it is refracted at the boundary of air and water, and enters the droplet, where the light is dispersed into the seven colors. The rainbow effect occurs because the light is then reflected inside the droplet and finally refracted out again into the air.