The left-hander came in to bat with South Africa placed at a shaky 331-7 but he batted sensibly under pressure to help his side declare their first innings at 455-9.
In reply, Sri Lanka were 30-0 when stumps were drawn for the day with Kaushal Silva batting on eight and Upul Tharanga on 20.
Tharanga, playing his first Test in six years, showed little signs of nervousness, hitting four boundaries in his 40-ball innings so far.
It was Duminy (100 not out) who stole the show with a superb rearguard action after opener Dean Elgar had laid the foundation for a good total with a 103-run knock on day one.
Also Read
Duminy, 30, frustrated the bowlers to take South Africa past the 400-run mark. His 206-ball effort contained 10 hits to the boundary including an exquisite cover drive off skipper Angelo Mathews.
Duminy, dropped on 82 by Dilruwan Perera, was given a standing ovation from his mates in the dressing room after he completed his fourth Test century.
He shared valuable partnerships with tailenders Vernon Philander and Morne Morkel (22) whose dismissal in the 167th over prompted new South African skipper Hashim Amla to declare the innings.