Justice in a man is like justice in a city (a polis, or city-state). He then argues that a just city is one in which there is harmony, cooperation, and a division of labor between all the castes. Farmers farm, carpenters build, and rulers rule. All contribute to the common good, and all lament when misfortune happens to any of them.
But in an unjust city, one group’s gain is another’s loss, faction schemes against faction, the powerful exploit the weak, and the city is divided against itself. To make sure the polis doesn’t descend into the chaos of ruthless self-interest, Socrates says that philosophers must rule, for only they will pursue what is truly good, not just what is good for themselves.
Glaucon’s thought experiment implies that people are only virtuous because they fear the consequences of getting caught—especially the damage to their reputations. Glaucon says he will not be satisfied until Socrates can prove that a just man with a bad reputation is happier than an unjust man who is widely thought to be good.
It’s quite a challenge, and Socrates approaches it with the above analogy.