Why Does a Compact Disc Produce a Rainbow?
A compact disc contains no rainbow colored dye. Its shifting colors are created by a spiral track so finely spaced that it separates ordinary white light.
Digital information on a disc is represented by microscopic changes arranged along one continuous spiral. The distance between neighboring turns is comparable to the wavelengths of visible light.
When white light strikes this repeating pattern, it reflects from many closely spaced parts of the surface. The reflected waves overlap. At particular angles, waves of one color reinforce one another, while other colors cancel or travel in different directions.
This process is called diffraction and interference. Because each color has a different wavelength, each leaves the disc most strongly at a different angle. Moving the disc, the light, or your head changes which wavelengths reach your eyes. The colors therefore slide and transform across the surface.
A prism also separates white light, but through a different mechanism. It bends wavelengths by different amounts as they pass through glass. A compact disc behaves more like a diffraction grating, a surface containing many regularly spaced lines.
The spiral was designed to guide a laser, not to create decoration. A player shines a single colored laser onto the track and detects changes in reflected light. Electronics interpret those changes as stored digital information.
A digital versatile disc stores more information partly because its track is more tightly spaced and its marks are smaller. A Blu ray disc uses an even shorter wavelength laser to read finer features.
The rainbow is therefore a visible side effect of information storage. The same microscopic pattern that organizes music into a spiral also sorts white light into its component colors.
Source: Fundamentals of Photonics, Bahaa Saleh and Malvin Teich - Optics, Eugene Hecht

Okunevy Island in Lake Vuoksa in Karelia, Russia
Source: By Dmitry A. Mottl