Here’s a video of Foucault talking about Discipline & Punish.(Well, an audio track with images) He explains his motivation for writing the book and the central question he sees posed by the development of the penal system in France. In short, there was a rapid growth of prisons in France. The prisons still functioned as institutions of punishment and an extension of the power of the sovereign, but they also became to be seen as institutions of reform. Reforming criminals required disciplinary techniques – which the reformers found in schools and the army. [The techniques for shaping character are the same].
So the modern prison system is not the same as the ancient prison/dungeon, it is more like other institutions of discipline such as educational institutions and the military. In turn, the expansion of the application of discipline gives rise to the development of further techniques that spread to other areas of society like factories. In each case, the system of discipline gives rise to a field of knowledge specific to the subject to affected: the student, the soldier, the criminal, the worker.