Walker joined the United States Army as a first lieutenant of the Regiment of Mounted Rifles in 1846, and served with distinction in the Mexican–American War, where he was breveted to captain for San Juan de los Llanos and was wounded at Molino del Rey. He was promoted to the full rank of captain June 1851. In 1858, he married Sophie Baylor, whose family was responsible for the naming of Baylor University. Walker remained in the Army until July 1861, when he joined the Confederate States Army as a major in the cavalry.