The incident occurred Wednesday afternoon at Fort Hood, the site of a notorious 2009 mass shooting carried out by an Army psychiatrist who was an extremist Muslim.
"At this time, there is no indication that this incident was related to terrorism, although we are not ruling anything out and the investigation continues," Milley told reporters Wednesday night.
He said four people were killed, including the gunman, who died of a self-inflicted wound. A total of 16 other people were injured. All of the victims, both the slain and injured, were military, he said.
Sources told CBS News the shooter had been identified as 34-year-old soldier Ivan Lopez.
Milley declined to name the soldier, saying his family had not been notified. But he did say that the soldier, who had served in combat for four months in Iraq in 2011, and was being treated for mental health issues and was on medication.
In Chicago, President Obama said he was following the situation closely.
"Any shooting is trouble. Obviously, this reopens the pain of what happened Fort Hood five years ago," the president said.
"They serve with valor. They serve with distinction, and when they're at their home base, they need to feel safe," Mr. Obama said. "We don't yet know what happened tonight, but obviously that sense of safety has been broken once again."
- Shooting at Fort Hood recalls deadly rampage at same base
- From Fort Bragg to Washington Navy Yard: Other military shootings
He got out, entered the second building, and opened fire again, Milley said.The base went into lockdown as the drama started to unfold. Warning sirens began going off and and all personnel were urged to shelter in place.
"There has been a shooting at Fort Hood and injuries are reported. Emergency crews are on the scene. No further details are known at this time," the post said in a brief statement.
Milley said military police responded quickly and the rampage came to a violent end when the suspect, who was armed with a .45-caliber Smith & Wesson semiautomatic piston, was confronted by a military policewoman.
"He was approaching her at about 20 feet. He reached into his jacket. She pulled out her weapon. He put his weapon to his head and shot himself in the head," Milley said.
It was "clearly heroic, what she did at that moment in time," the general said, but added, "She did exactly what we expect of a United States soldier."
Fort Hood remained on lockdown for several hours.
Tayra DeHart, 33, said she had last heard from her husband, a soldier at the post, that he was safe, but that was hours earlier.
"The last two hours have been the most nerve-racking I've ever felt. I know God is here protecting me and all the soldiers, but I have my phone in my hand just hoping it will ring and it will be my husband," DeHart said.
Brooke Conover, whose husband was on base at the time of the shooting, said she found out about it while checking Facebook. She said she called her husband, Staff Sgt. Sean Conover, immediately to make sure he was OK.
"I just want him to come home," Conover said.
Milley said the suspect was married and had a family, but did not elaborate. He said the soldier had been transferred to Fort Hood from another military installation in February.
He said the suspect had apparently suffered a "traumatic brain injury" in the past, but it was not combat-related. The shooter had been being treated for depression, anxiety, "and a number of other psychiatric issues," Milley said. He was on medication.
The general said the suspect had been undergoing a "diagnosis process" to determine whether he had post-traumatic stress disorder, but said no diagnosis had been made.
"We have to find all those witnesses, the witnesses to every one of those shootings, and find out what his actions were, and what was said to the victims," a federal law enforcement official, speaking on condition of anonymity because he was not authorized to discuss the case by name, told The Associated Press.
The official said authorities would begin by speaking with Lopez's wife and also expected to search his home and any computers he owned.
Milley praised the emergency crews from surrounding communities who rushed to the base, home of the Army's 1st Cavalry Division.
Three of the eight at the hospital were in critical condition and the others were seriously hurt, officials said.
The victims, who were transported by either helicopter or ambulance, suffered gunshot wounds, some in the extremities, others in the abdomen, chest, and neck.
Some were shot repeatedly, officials said.
Hasan, who was left paralyzed when he was shot by police responding to the shooting spree, has been sentenced to death for the rampage.
After that shooting, the military tightened security at bases nationwide. Those measures included issuing security personnel long-barreled weapons, adding an insider-attack scenario to their training and strengthening ties to local law enforcement. The military also joined an FBI intelligence-sharing program aimed at identifying terror threats.
In September, a former Navy man opened fire at the Washington Navy Yard, leaving 13 people dead, including the gunman.
After that shooting, Defense Secretary Hagel ordered the Pentagon to review security at all U.S. defense installations worldwide and examine the granting of security clearances that allow access to them.
Asked Wednesday about security improvements in the wake of other shootings at U.S. military bases, Hagel said, "Obviously when we have these kinds of tragedies on our bases, something's not working."
"Events in the past have taught us many things here at Fort Hood," he said. "And we know that the community is very resilient."
Asked whether he wondered why the base had been the scene of two mass shootings, Milley told reporters, "I wasn't thinking about 'not again' or anything like that. Right now my concern is with the families, those that were injured and those that were killed."
He did say, however, that "the response from the law enforcement and the medical units displayed lessons learned from the previous case."
Gen. Martin Dempsey, chairman of the Joint Chiefs of Staff, offered sympathies to the Fort Hood community on Wednesday night.
"Our thoughts and prayers are with the Fort Hood community in the aftermath of this tragedy. Many questions remain and our focus is on supporting the victims and their families," Dempsey said. "This is a community that has faced and overcome crises with resilience and strength."
Sen. John Cornyn, R-Texas, asked Americans to pray for the victims and their families.
"Tonight, Texans' hearts are once again very heavy. The scenes coming from Fort. Hood today are sadly too familiar and still too fresh in our memories," he said. "No community should have to go through this horrific violence once, let alone twice."