I have read that the phial contained a part of Eärendil's star, but do we know how that came to be in Galadriel's possession?
The phial did not contain part of Eärendil's star, it contained light from it (Farewell to Lórien):
She held up a small crystal phial: it glittered as she moved it, and rays of white light sprang from her hand. 'In this phial,' she said, 'is caught the light of Eärendil's star, set amid the waters of my fountain.'
Therefore there is no difficulty here.
To clarify re: the storage of light; Earendil's star was the light of the Silmaril (which Beren and Lúthien stole from Morgoth), which in turn contained the light from the Two Trees. The answer to how light could be stored is therefore: "it's magic".