The first thing you get when you start canning are fruit flies, millions of them! It is important to keep everything scrupulously clean and covered to reduce them and an effective trap is essential.
I've had great success with this:
Simply a cup or a glass jar with yeast (about 1 tsp.) and vinegar (about 1/4 cup). Stretch plastic cling wrap tightly over it and puncture with a sharp pencil to make a few (5ish) small holes. Sometimes I add a rubber band to help keep the plastic wrap in place.
The fruit flies are attracted to the yeast and vinegar and go in through the little holes, somehow they can't figure out how to get back out and eventually fall into the vinegar.
The jam peaches we brought home today were covered with fruit flies, we shook the box gently till all had taken flight, covered it with a towel to keep them out and set them up their very own trap. I must have 4 or 5 of these set up around the house, wherever I saw them congregating.