Walker volunteered for U.S. Army service in the Mexican–American War and was appointed first lieutenant in the infantry on February 27, 1847. On April 9, 1847, he was assigned to the 1st U.S. Regiment of Voltigeurs and Foot Riflemen, a light infantry regiment. He was regimental adjutant between May 1, 1847 and June 15, 1847. Walker was appointed a brevet captain for his role in the Battle of Chapultepec, September 13, 1847. With the disbanding of the Voltiguer regiment at the end of the war, Walker was discharged on August 31, 1848.