Luis Reece claimed career-best figures of 7-20 as Derbyshire ended Day Two needing eight more Gloucestershire wickets for victory.
The all-rounder returned the third best Derbyshire bowling analysis in the 21st century as Gloucestershire were all out for 163 in their first innings.
Alex Hughes then hit a battling 55 not out as the hosts set Gloucestershire 179 runs to win with ten overs to face in the evening.
Lockie Ferguson struck twice to leave the visitors 29-2 and set up a thrilling chase heading into Day Three.
Four-day cricket is back! Derbyshire host their final Specsavers County Championship match of the season against Gloucestershire from Monday 24 September. Buy your tickets in advance and save.