Continuum gamma-ray emission produced by interactions of cosmic rays with interstellar matter and radiation fields is a probe of non-thermal particle populations in galaxies. After decades of continuous improvements in experimental techniques and an ever-increasing sky and energy coverage, gamma-ray observations reveal in unprecedented detail the properties of galactic cosmic rays. A variety of scales and environments are now accessible to us, from the local interstellar medium near the Sun and the vicinity of cosmic-ray accelerators, out to the Milky Way at large and beyond, with a growing number of gamma-ray emitting star-forming galaxies. Gamma-ray observations have been pushing forward our understanding of the life cycle of cosmic rays in galaxies and, combined with advances in related domains, they have been challenging standard assumptions in the field and have spurred new developments in modelling approaches and data analysis methods. We provide a review of the status of the subject and discuss perspectives on future progress.