Why do we see a rainbow of colors reflected off a CD or DVD?

The pits are in parallel circular tracks with a distance of 1.6 micrometers. These act as a diffraction grating. Normally this is a reflection grating, but one can make a transmission grating by removing the metal layer (easiest in recordable disks).

Here is an image that I made in transmission with a cover disk without a recording layer. The mercury street light can be seen in the middle.

enter image description here

We often think that light goes in straight lines, and reflection angle equals incidence angle, but that is only a statistical property of bulk light. An individual photon can go in any direction after a disturbance (at least we can't predict it), but paths whose lengths are much longer than the straight line path will cancel because the phase at the detector (eye) is affected by the path length. When the apparent distances between obstacles match the wavelength (color) of light, that color is reinforced (not cancelled, because the cancelling photons went through the gaps between the obstacles). For any colored spot that you see, there are several paths whose lengths differ only by a multiple of the wavelength. Other colors don't appear there because their wavelengths are not exact divisors of the multiple path lengths, so they can cancel out. Reflection and diffraction merely refer to the two sides of the obstacles: reflected light bounces off the obstacles and diffracted light goes through the gaps.

On a CD, the important distance is that between the 'data tracks', not the thickness of the disk or the spacing between 'bits' (a blank CD-R already diffracts). A CD is pressed with tracks (either with bit pits, or just a groove for photosensitive dye), and the aluminized layer is placed over that. It is the gap between tracks that reflects the most light (or passes it if you remove the backing). Depending on viewing angle, the apparent distance between tracks will be a multiple of certain wavelengths, which will be the color you see there.