One member of Thailand's security forces has been killed and two wounded in a raid attempting to stop a soldier on a rampage that has now killed 21 people, the health minister has said.

Photo: AFP PHOTO/ MCOT Public Company Limited

Public Health Minister Anutin Charnvirakul gave no further details to reporters outside the Terminal 21 shopping centre in Nakhon Ratchasima, also known as Korat, where the gunman was holed up.

A series of explosions and more gunfire could be heard from inside the mall.

A defence spokesperson said earlier Jakraphanth Thomma, a junior officer, had killed his commanding officer before stealing weapons from a military camp, then driving to the city centre and entering the shopping complex.

The suspect, whose motives remain unclear, posted images of his attack on social media sites.

Photo: AFP PHOTO / THAI ROYAL POLICE

Defence ministry spokesperson Lt Gen Kongcheep Tantravanich said hundreds of people had been brought out of the complex safely, but there could be dozens still in the building.

The Bangkok Post reported earlier that the suspect, who it said was 32 years old, had taken hostages, but this has not been officially confirmed.

The suspect's mother had been brought to the shopping centre to try to persuade him to give himself up.

One of the people freed told the BBC how she and others hid in a bathroom on the fourth floor, before fleeing to the second floor and hiding under a restaurant table for three hours, hearing at least four gunshots before she saw some soldiers and could get to safety.

Gen Kongcheep earlier confirmed 20 people had been killed so far.

The attack began in the late afternoon at the Suatham Phithak military camp, where the commanding officer, named by the Bangkok Post as Col Anantharot Krasae, was killed.

The Post said a 63-year-old woman and another soldier were also killed there.

The suspect seized arms and ammunition from the camp before taking a Humvee-type vehicle.

He then opened fire at a number of sites before arriving at the Terminal 21 shopping centre.

Local media footage appeared to show the suspect getting out of his vehicle and firing shots as people fled.

CCTV footage showed him inside the shopping centre with a raised rifle.

Other footage showed a fire outside the building, with some reports saying it was caused by a gas canister that exploded when it was hit with a bullet. One of the suspect's social media posts features an image of himself with the fire in the background.

Prime Minister Prayuth Chan-ocha is following developments and expressed condolences to the families of those killed, a spokeswoman said.

The public health minister has put out an appeal for people to donate blood at hospitals in the area.

What did the suspect post on social media?

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" and "nobody can avoid death".

Facebook has now taken the page down.

It said: "Our hearts go out to the victims, their families and the community affected by this tragedy in Thailand. There is no place on Facebook for people who commit this kind of atrocity, nor do we allow people to praise or support this attack."

- BBC / Reuters