A two-component Coulomb gas confined by walls made of ideal dielectric material is considered. In two dimensions at the special inverse temperature β=2, by using the Pfaffian method, the system is mapped onto a four-component Fermi field theory with specific boundary conditions. The exact solution is presented for a semi-infinite geometry of the dielectric wall (the density profiles, the correlation functions) and for the strip geometry (the surface tension, a finite-size correction of the grand potential). The universal finite-size correction of the grand potential is shown to be a consequence of the good screening properties, and its generalization is derived for the conducting Coulomb gas confined in a slab of arbitrary dimension ≥2 at any temperature.