Same as for a doctor anywhere else: generally, 4 years for a bachelor's degree; 4 years of medical school (MD or DO), followed by internship (1 year) & residency (3 years minimum) - strictly speaking not "school" because working as a junior doctor undergoing further training, & getting paid!
Many medical officers are recruited from civilian medical schools; others attend med school whilst serving (Uniformed University of Health Sciences), & most do internship/ residency in military hospitals.
Pretty well all medical specialties found in the civilian medical world are also available in the military, but there's particular emphasis on areas like emergency medicine, trauma/ critical care, anesthesiology, orthopedics, neurosurgery, public health, epidemiology, remote area medicine, psychiatry, aeronautical & nuclear medicine. But there's also a big demand for family medicine, pediatrics, OG etc - general care of personnel & their families.
The Armed Forces also need dentists, optometrists, podiatrists, & vets: as with MDs/ DOs their training is identical to that in civilian medicine.