Belhassen Oueslati did not specify whether the gunman, who was also killed, was among the seven dead.
Oueslati said 10 others were injured, including one person who was in a serious condition.
It wasn't immediately clear what motivated the soldier.
The shooting at the Bouchoucha barracks was about a kilometre away from the National Bardo Museum where 22 people mostly tourists were killed in a terror attack on March 18.
Oueslati said the situation was under control by mid-morning.