Do eye doctors only do eye exams? Do they treat infections?

No, yes. Eye doctors focus on diagnostic and therapeutics for the eyes, but eyes are manifestations of systemic disease so they can treat infections and other things. Based on a physician's comfort level and access or lack thereof to specialists, they will do other things.
Of course! An ophthalmologist is a medical doctor (md or od) and a surgeon. We treat everything from glasses to injury, infection, cataracts, retinal detachments etc. Much more than just infections.