We report the development of quantum microscopic theory of quasi-resonant dipole-dipole interaction in the ensembles of impurity atoms imbedded into transparent dielectric and located into Fabry-Perot cavity. On the basis of the general approach we study the simultaneous influence of the cavity and resonant dipole-dipole interaction on the shape of the line of atomic transition as well as on light trapping in dense impurity ensembles. We analyze this influence depending on the size of the ensemble, its density, as well as on r.m.s. deviation of the transition frequency shifts caused by the symmetry disturbance of the internal fields of the dielectric medium. Obtained results are compared with the case when the cavity is absent. We show that the cavity can essentially modify cooperative polyatomic effects.