A nonlinear self-consistent theory has been constructed and used to investigate numerically the wakefield excitation in multilayered dielectric resonators by relativistic electron bunches. Analytical expressions for solenoidal and potential components of an excited electromagnetic field have been derived. The excitation of a five-zone dielectric resonator by relativistic electron bunches was numerically investigated and comparison was made between the longitudinal distribution of an axial electric field and the results obtained previously for a corresponding problem in the waveguide formulation. The necessity of optimizing geometrical parameters of the resonator to reduce mode amplitudes nonresonant with a bunch, and to obtain a symmetric distribution of the longitudinal electric field component in the drive and accelerating channels, has been demonstrated.