SN 2008D was discovered while following up an unusually bright X-ray transient (XT) in the nearby spiral galaxy NGC 2770. We present early optical spectra (obtained 1.75 days after the XT) which allowed the first identification of the object as a supernova (SN) at redshift z = 0.007. These spectra were acquired during the initial declining phase of the light curve, likely produced in the stellar envelope cooling after shock breakout, and rarely observed. They exhibit a rather flat spectral energy distribution with broad undulations, and a strong, W-shaped feature with minima at 3980 and 4190 Å (rest frame). We also present extensive spectroscopy and photometry of the SN during the subsequent photospheric phase. Unlike SNe associated with gamma-ray bursts, SN 2008D displayed prominent He features and is therefore of Type Ib.Partly based on observations made with ESO telescopes at the La Silla Paranal Observatory under program 080.D-0526, with the Nordic Optical Telescope, operated on the island of La Palma jointly by Denmark, Finland, Iceland, Norway, and Sweden, and with the United Kingdom Infrared Telescope, which is operated by the Joint Astronomy Centre on behalf of the Science and Technology Council of the UK.