A fly in the ointment is an old idiom still in use today. It means one problem or unpleasant element in a situation which is otherwise perfect, or at least very good. For example, you might say: "I love my job, and my colleagues are really nice. The only fly in the ointment is the boss - he's so difficult." This would imply that your boss is the only thing you don't like about your job.
The idea behind this idiom is that ointment is something good - you use it to soothe painful skin or improve your appearance, so basically a smooth, peaceful situation can be compared to ointment. On the other hand, flies are associated with dirt, disease and general unpleasantness. If you have a fly in your jar of ointment, the jar is contaminated and you will not want to use it again, or at least until you've got rid of the fly. So it really is quite a logical idiom.
The idea behind this idiom is that ointment is something good - you use it to soothe painful skin or improve your appearance, so basically a smooth, peaceful situation can be compared to ointment. On the other hand, flies are associated with dirt, disease and general unpleasantness. If you have a fly in your jar of ointment, the jar is contaminated and you will not want to use it again, or at least until you've got rid of the fly. So it really is quite a logical idiom.