These lectures contain an introduction to instantons, calorons and dyons of the Yang--Mills gauge theory. Since we are interested in the mechanism of confinement and of the deconfinement phase transition at some critical temperature, the Yang--Mills theory is formulated and studied at nonzero temperatures. We introduce ``calorons with a nontrivial holonomy'' that are generalizations of instantons and can be viewed as ``made of'' constituent dyons. The quantum weight with which these calorons contribute to the Yang--Mills partition function is considered, and the ensuing statistical mechanics of the ensemble of interacting dyons is discussed. We argue that a simple semiclassical picture based on dyons satisfies all known criteria of confinement and explains the confinement-deconfinement phase transition. This refers not only to the SU(N) gauge groups where dyons lead to the expected behaviour of the observables with N, but also to the exceptional G(2) group whose group center, unlike SU(N), is trivial. Despite being centerless, the G(2) gauge group possesses confinement at low temperatures, and a 1st order deconfinement transition, according to several latest lattice simulations, indicating that confinement-deconfinement is not related to the group center. Dyons, however, reproduce this behaviour.