A defence ministry spokesman told BBC Thai that Jakraphanth Thomma, a junior officer, had attacked his commanding officer before stealing a gun and ammunition from a military camp.
He then opened fire at a Buddhist temple and at a shopping centre in the city, north-east of Bangkok.
The suspect is still at large.
Local media footage appears to show the suspect getting out of a Humvee-type vehicle in front of the Terminal 21 shopping centre in the Muang district and firing shots as people flee. Other footage showed a fire outside the building, with some reports saying it was caused by a gas canister that exploded when shot at.
Authorities have been sealing off the centre as they try to track down the suspect, who is reportedly inside the building. Police have warned people to stay at home.
The Bangkok Post reported that the suspect, who it said was 32 years old, had taken hostages inside the building, but this has not been officially confirmed. More gunshots have reportedly been heard inside the building.
The suspect’s motive remains unclear.
However, he posted on his social media accounts during the attack, with one post on Facebook asking whether he should surrender.
He had earlier posted an image of a pistol with three sets of bullets, along with the words: “It is time to get excited.”
The Bangkok Post said the dead commander was Col Anantharot Krasae, and that a 63-year-old woman and another soldier had been killed at the military camp.
Prime Minister Prayuth Chan-ocha is following developments and expressed condolences to the families of those killed, a spokeswoman said.
Featured Image Origin: Express