IBM originally approached Gary Kildall to make an operating system for their first PC.
Gary had an OS product called CP/M, which was popular among early hobbyists and on 8-bit home computers of the late 1970s and early 1980s.
They were unable to reach an agreement, so IBM went to Bill Gates.
Gates didn't have an OS to offer, so he bought out QDOS and hired its author Tim Paterson (whose name is embedded in MS-DOS).
Paterson had designed QDOS as a work alike to CP/M, which was compatible with CP/M files.
The early versions of MS-DOS were enhanced QDOS.
Speculation was and always has been rampant that MS-DOS was copied in some way from CP/M.
The rest is history.