Do a search for "fungus gnats".
Look carefully at the pictures.
They match up?
That's good news.
There are flyers like root aphid adults that are much harder to eradicate.
The adult gnats don't do any damage to your plants, but their kids, (larvae), are chowing down on your roots.

The search results will tell you how to deal with them.

Of course the best treatment is prevention.
Fungus gnats hunt by scent.
They sniff for root rot and fungus to assure their hatch a food supply.
They need to be able to find your roots, so anything that jams up their sniffer will throw them off the scent or physically block them.

Some folks use sand as a barrier.
It's messy during transplants and the gnats can and do lay their eggs in the weep holes at the bottom.
One guy, puts his containers in mesh bags and cinches it up around the stem to lock them out.

I use dryer sheets.
Lay them on top of the soil to break the egg laying cycle and I put one in the weep tray.
Works a treat!
Have not had an F.G. in 2 years now.

Aloha,
Weezard