When Joseph son of Jacob (Jacob surnamed Israel which means: God's servant).. so when Joseph was taken to Egypt, as the story is well known, he preached monotheism: that God is One to Whom the exclusive devotion is due. And that God is to be glorified, and none else to be worshiped
Then God gave Joseph authority in Egypt, and he ruled like the prime minister of the present time
So the Egyptians were in good condition on account of Joseph's teachings and instructions
Then His eleven brothers together with his father and aunt came and joined him in Egypt
All of them prospered in Egypt, while the countries round about them were in bad condition and famine
Later on,the Israelite, in one way or another, fell into the idolatry of the Egyptian, and started to sanctify the gods and idols of the Egyptian, that is after the family of the king of Joseph were ousted, and another family of Pharaohs came to rule.
That was Ahmose and his sons: they considered the Israelite the allies of the previous royal family and started to persecute them for this reason
God - be glorified - told us the story of Joseph and what he said to the two inmates who were with him in the prison
Quran 12: 37-40 which mean
Such [knowledge of the dream interpretation] is some of that my Lord has acquainted me with
I have forsaken the religion of a folk [who are associaters: worshipping the idols with God, and ]who believe not in God [alone], and [moreover] of the Next Life they are deniers
And I have followed the religion of my fathers: Abraham, Isaac, and Jacob; we ought not to associate anything with God; that is [some] of God's bounty to us and to people, but most of people give no thanks [about God’s bounties to them.]
O my two companions in prison, which is better: many differing lords [of stone, silver, and copper which neither harm nor profit, or is God: the One, the Omnipotent
You worship none, apart from [God], other than mere names which you and your fathers have named, concerning which God has not revealed any authority
The decision [about the worship] is up to God [alone]. He has commanded [in the heavenly books] that you should worship none other than He [alone]
That is the religion of [Prophet Jacob] the guardian [on his sons and his people], but most of people do not know [the truth.]
http://quran-ayat.com/pret/12.htm#a12_37