How does my doctor know I have a herniated disk?

You tell him . Most diagnoses are made when you listen to what the patient complains about and then you do a thorough exam. 90% of the time a doctor will make the diagnosis with imaging/testing usually confirming it or helping to make the diagnosis in the other 10%.
Maybe Exam? Unsure without much more details. But a thorough medical exam and history often tells the story. Xray and MRI can help that more.
Exam, MRI. If your complaints and physical examination suggest a disc herniation, the diagnosis can be confirmed with an mri.