How is it possible to shield eletomagnetic waves?

I've learned the Maxwell equations and how light is described as an electromagnetic field. But then the teacher just jumped to geometric optics.

I'm trying to understand light in terms of electromagnetic waves. How can something block a electromagnetic wave, like a mirror? Something my teacher told me is that, when the electromagnetic wave passes a metal, since the metal has free electrons, the electrons follow the changing electric field, producing a current and absorbing energy, so absorbing light. But how can you absorb electric field? The only thing I can think about is producing another field that counter-interacts with the original, thus canceling it, but how is it possible to the field produced happens to be exactly opposite to the original? Also, how can a dielectric material absorb light, if it does not free electrons?

Indeed, a shadow is the sum of the incident field and the fields produced by the electrons in the opaque object. Those are opposite in phase. It is the reason behind Babinet's principle.

Since the electromagnetic wave is made up of oscillations in the electric and magnetic fields, anywhere that does not allow those fields will not allow EM waves. So a conductor is a perfect example: Since EM fields cannot exist within the conductor, it will be opaque to EM waves beyond some small skin depth. This works because the free charges rearrange themselves and influence the field, until the inside of the conductor doesn't "see" a field anymore.

A Faraday cage is another example, and it operates in the exact same manner except that it cannot be cancelling all of the fields or else we couldn't see inside of the cage! There is a length scale involved based on the spacing in the grating, and light with smaller wavelengths is evidently unaffected.

You can understand reflection a few different ways: Classically you could say the photons collide and rebound from the reflecting atom; quantum mechanically, the reflecting atom absorbs a quantum of energy and enters an excited state, then re-emits the light and relaxes again. In this case, the atom's not really absorbing a field, but rather a small quantity of energy in the form of a photon. Upon re-emitting that photon, the EM fields that correspond to that frequency of light appear and begin to propagate.

...how is it possible that the field produced happens to be exactly opposite to the original?

I's just add that the cancellation is never perfect even with good conductors (hence, skin effect) and not good at all with mediocre conductors (say, semiconductors) or very thin conductors (not sufficient skin depth). The cancellation is also limited to moderate frequencies, when the electrons can keep up with the field changes: at very high frequencies, like visible light, that cancellation mechanism won't work anymore and the waves will be dealt with at the atomic level.

Also, how can a dielectric material absorb light, if it doesn't have free electrons?

Many dielectrics, in fact, cannot absorb light - for instance glass is largely transparent to visible light. In cases when dielectrics do absorb light, there is always some electrical mechanism, on the atomic or molecular level, involved.

For instance, dielectrics could have some embedded metal atoms that are capable of absorbing photons of certain frequencies or the molecules in some dielectrics could be polarized and vibrate at certain frequencies absorbing and emitting photons (scattering) or, perhaps, the frequency (photon energy) of light is so high that it can excite electrons in the atoms of a dielectric (UV absorbed by glass).