Fruit Flies and Storage of Fresh Produce
I've never had luck keeping them out of food. Sealed containers work, but cause fruit to ripen and spoil quickly, and they are small enough to get in anything with an opening.

However, a simple fruit fly trap can keep them in check:

Cut a 2l soda bottle where the top taper ends (above the label). Add a few drops dish soap to a few tbsp of apple juice, beer or cider vinegar. Pieces of fruit can also be used. Invert the severed top of the bottle (sans cap), and seal with a piece of duct tape around the edge. 

Set near the fruit and wait. Open it up to empty every few days.

Google will give you a variety of other designs that you can build if you are more ambitious.