Upon graduation, Rains was commissioned as a second lieutenant in the infantry. Rains served in the Seminole Wars and was promoted to captain on December 25, 1837, and brevetted major on April 28, 1840, for his service against the Seminoles near Fort King, Florida, where he routed a superior force, and was twice severely wounded. One of his wounds was considered mortal, and several obituary notices of him were published, however he survived the wounds. Rains took part in the Mexican War and was engaged in the defense of Fort Brown in May 1846. When General Pedro de Ampudia demanded the surrender of the fort, Rains cast the deciding vote against surrender in a council of officers. Following the Battle of Resaca de la Palma he was ordered to the United States on recruiting duty, and organized a large part of the recruits for General Winfield Scott's campaign. Rains was promoted to major of regulars on March 9, 1851, and from 1853 until the Civil War he served on the Pacific Coast, where he took part in the Indian Wars. In 1855 he was brevetted to brigadier general of Washington Territory volunteers. Rain was the commanding officer of Fort Humboldt from 1856 through 1860. He was promoted to lieutenant colonel of regulars on June 5, 1860, but resigned his commission on July 31, 1861, and joined the Confederate States Army, in which he was commissioned a brigadier general and got command of a brigade in the Richmond area.