Although "доктор" is mostly synonymous with "врач" in the context of medicine (outside of that context, "доктор наук" is an academic degree equivalent to Habilitation rather than PhD), it is interesting to discuss subtle differences in their usage.
"Доктор" is used as a title, but "врач" is not. When I speak to a doctor, I can say "Спасибо, доктор!" but not "Спасибо, врач!". When I speak about a specific doctor who was already referred to before, I can say "доктор Иванов" but not "врач Иванов" (although I can say "врач Леонид Иванов" — usually without omitting the first name — when first mentioning that person, as in "Leonid Ivanov, a doctor").
When not used as a title, "доктор" sounds slightly informal and old-fashioned. In official documents, a doctor is virtually always referred to as "врач". There are a lot of organizations with the words "Ассоциация врачей" in their title, but virtually none have "Ассоциация докторов". When I specify a doctor's specialty, I virtually always use "врач": "врач-педиатр", "врач-стоматолог"; I can of course say just "стоматолог", but "доктор-стоматолог" sounds somewhat unnatural, although not wrong. A mother speaking to a child could say both "Мы сейчас пойдём к врачу" and "Мы сейчас пойдём к доктору" (We're going to the doctor now), the latter being slightly more probable due to the popularity of the tale "Доктор Айболит".