This begins all the way back with Abel. As a shepherd, his sacrifice of a firstborn from his flock is the first real hint of Jesus' ultimate sacrifice for all people. Abel, too, is murdered for his role as a shepherd. Later, Noah also plays the role of shepherd as caretaker for all of the animals of the world. Like Abel, Noah brings ritually clean animals as sacrifice to celebrate their deliverance.
Abraham was wealthy due to the size of his flocks. His willingness to sacrifice his son (if not his firstborn) is another allusion to the coming sacrifice of Jesus. His descendants are also shown as shepherds with his flocks going to Isaac and then to Jacob. Jacob's son, Joseph, also watched his father's sheep, but his brothers' jealousy of their father's love led them to selling him to slavers--a move that ultimately saved the people, but found them later enslaved in Egypt.
It is from Egypt that Moses flees as a murderer but becomes a shepherd. While tending the flocks of his father-in-law, Moses comes across the burning bush at Mount Horeb. Thus, it is as a shepherd that Moses is given the job to be a shepherd for his people, leading them out of enslavement in Egypt and to the Promised Land.
Finally, King David--from whose line Jesus is descended, as had been promised--worked as a shepherd in his youth. He fought off both a lion and a bear in protection of his father's sheep. It is while David is tending the sheep that Samuel visits David's father, Jesse, while in search of a new king for Israel. When David was brought in from shepherding, the Lord points him out to Samuel who anoints David, powerfully filling him with the Spirit of the Lord.
Thus, we Jesus claims the mantle of the Good Shepherd, He is making a connection to the powerful patriarchs of the past. It's more than a metaphor. He is the ultimate fulfillment of the promises that were made to each of them.