From the wonderful National World War I Museum and Memorial in Kansas is the following explanation of how the nickname came about:
Indelibly tied to Americans, “Doughboys” became the most enduring nickname for the troops of General John Pershing’s American Expeditionary Forces, who traversed the Atlantic to join war weary Allied armies fighting on the Western Front in World War I.
The Great War marked the first time in history the United States sent soldiers abroad to defend foreign soil. The French ecstatically welcomed the first wave of soldiers. “Vive l’Amèrique!” came the shouts at the edge of a Boulogne pier as Pershing steamed into port. In an emotional arrival ceremony at the Marquis de Lafayette’s tomb, Col. Charles E. Stanton declared to the crowd, “Lafayette, we are here!” suggesting Americans had come to repay an old debt to the French dating back to when the colonies stood virtually alone in the American Revolution.
But what to call the Americans? “Yanks,” “Sammies,” “Pershing’s Crusaders” – these were just some of the names used to label America’s enlisted men in World War I. Pershing’s Crusaders and Sammies (for Uncle Sam’s troops) made some appearances in advertising and propaganda posters, but those labels weren’t well liked by the troops, many of whom preferred to be called Yanks.
Though there are many origin stories for “Doughboys,” the nickname that finally stuck, there is one with strong historic support. Likely, the name attached early to the Americans from U.S. military operations on the Mexican border.
Reconciliation with Mexico had just concluded in 1916 when marching foot soldiers in Pershing’s Expeditionary Force traveled south of the border to fight rebel Pancho Villa. Covered in white adobe dust, the foot soldiers were called “adobes” or “dobies” by mounted troops. Within a few months, these dobies, or Doughboys, were redeployed to Europe.
“Over There” is a 1917 hit song written by George M. Cohan that was popular with United States military and public during both world wars. It was a patriotic song designed to galvanize American young men to enlist in the army and fight the “Hun”. The song is best remembered for a line in its chorus, “The Yanks are coming.”