The color of a soap bubble is not exactly like that of a rainbow but yes, it is colorful, thus reminding us of a rainbow. So, the question is why it is so colorful?
As white light is incident on a bubble, some of it is reflected from the outer surface of bubble's film and some enters the film and comes out after being reflected back and forth between the inner surface and the outer surface.
The color that we see depends on the interference of these reflected waves. When a wave enters the film and comes out, it undergoes change in its phase. The shift in phase depends on the wavelength of the light and on the thickness of the film. Therefore, for a given thickness, there is different phase shift for different wavelengths i.e. for different colors. Thus, the interference is constructive for some colors (i.e. waves add up) and destructive for some colors (i.e. waves cancel out). Thus color that we see depends on thickness.
Thicker films cancel out longer wavelengths. Therefore, if you start from a very thick film and make the film thinner, then first red is cancelled out, after some further thinning yellow and so on.
The film of a soap bubble does not have uniform thickness. This is because gravity pulls the liquid down and this makes the thickness nonuniform. Since bubble's color depends on thickness and thickness varies, therefore we see different colors.
I mentioned above the effect of film's thickness. Interference depends also on the angle at which the light strikes the film. Therefore, even if the film had uniform thickness, we would see different colors because light rays strike the bubble at different angles. However, thickness is not uniform because of gravity.