A rainbow refracts white light into the wavelengths of the individual colours. The colours appear in order, according to their wavelengths, from longest (red) to shortest (violet). A rainbow actually includes millions of subtle colours as we progress through the spectrum, but our eyes perceive them as seven bands.
But why not colours like magenta? Magenta coloured light is created by mixing light of red and blue wavelengths. Since red and blue are not close together on the spectrum, magenta will not appear naturally in a rainbow.
Human eyes can also only see light within the visible spectrum, i.e. within the wavelengths of the electromagnetic spectrum visible to the human eye. A rainbow also includes infra-red and ultra-violet bands but we cannot see them. However animals that can see a wider range of visible light will see more colours in a rainbow that we do.