For everything He created and formed was according to His Will (may it be blessed), [that is] only to be good to the creations. So too His Will is that we walk in His ways. As it says “and you shall walk in His Ways” (Devarim 28:9) שכל מה שברא ויצר היה רצונו יתברך רק להיטיב עם הנבראים, כן רצונו ית׳ שנהלך בדרכיו כאמור “והלכת בדרכיו”,
Now Rav Shimon Shkop explains how bestowing good on others is the essence of being in the Image of G-d.
Why did Hashem create the universe? The truth is, we can’t ever know; humans are incapable of knowing the “Mind” of the Creator — His “Thoughts” are Infinite, Transcendent, and do not resemble our trains of thought that evolve within time. What we can try to answer is: What did Hashem show us of why He created the universe? What does G-d want us to emulate?
Well, whose need does creation fill? It can’t be Hashem’s need, as His Perfection precludes His having any needs. Hashem thus had to be addressing the created’s needs. Creation is therefore (again, to the extent we can understand it) an act that is purely the bestowal of good on others — “[E]verything He created and formed was … only to be good to the creations.” So too His Will is that we walk in His ways.
The Ramchal phrases it thus, “It is the nature of good to have someone to whom to be good.” (Derech Hashem 1:2:1) And centuries earlier, on the other side of the qabbalah-rationalism spectrum Rav Saadia Ga’on reached the same conclusion in Emunos veDei’os. The human being can be defined as a receptacle for emanations of Divine Good and sustenance, in shorter and therefore useful jargon: “a keli for shefa“. Simply and personally put, you and I exist so that G-d would have a recipient of His Good.
And yet, there is much unhappiness in this world. Hashem could have insured that receiving shefa (emanations of Divine Good and sustenance) would make us happy, but He didn’t. While it is important to note the difference between bestowing good and making happy, that isn’t enough to explain why this would be true. Suffering, even if it is in some cosmic sense “good”, is a lack of goodness in how that cosmos was created. After all, we are speaking of the Bestower who defined the emotion of happiness, and created within us the mechanisms that generate it. He could have chosen to make the two identical, that true good and only true good would make us happy. Man is therefore lacking in two ways: we are not receiving His full goodness, and amongst that Divine Good that we lack is that very union between what we want and what is good for us.
We are left with a dilemma. We would conclude that Hashem created imperfect recepticals, and that is why we are not receiving the full shefa. However, we would need to explain why a Perfect Creator would make beings that don’t perfectly fulfill His purpose for them.
In the Torah, Hashem introduces the idea of creating people with the words “let Us make man in Our Image, like our Semblance” (Bereishis 1:26). The ultimate good the Creator has to share with us is His own “nature”, the gift of being free-willed, having the capacity to make meaningful decisions, to create, and to use that creation to address the needs of others.
There is unhappiness in the world so that we have the opportunity to give. As Rav Shimon puts it, Hashem created everything so that He could be good to them and part of that is that “His Will is that we walk in His ways”. Counter-intuitively, the creation of a universe that has no lacks would actually lack the greatest good — the opportunity to be in Hashem’s Image, to be a giver.
Eav Eliyahu E. Dessler takes a similar position on what it means to be in the “Image” of G-d. See the following, from the beginning of his “Qunterus haChessed” in Michtav meiEliyahu vol. 1:
When the Almighty created human beings He made them capable of both giving and taking. The faculty of giving is a sublime power; it is one of the attributes of the blessed Creator of all things. He is the Giver par excellence; His mercy, His bounty and His goodness extend to all His creatures. His giving is pure giving for He takes nothing in return. He can take nothing for He lacks nothing, as the verse says, “…If you are righteous what do you give to Him?”
Our service to Him is not for His need but for our own, since we need a means of expressing our gratitude to Him.
Man has been granted this sublime power of giving, enabling him too to be merciful, to bestow happiness, to give of himself. “G-d created man in his own image.”
 (All honorifics, such as “may it be blessed” and “may His memory be a blessing” appear in the original as acronyms of common idioms that the reader could read without losing their train of thought. Since this is impossible in translation, I chose to hereafter omit them. For similar reasons, “Moses our teacher” or “Moses our teacher, peace be upon him”, I usually rendered simply “Moses” for readability.)