It's been about a decade since I've read The Hobbit or The Lord of the Rings, but I recently re-watched the movies (all 6) and from the standpoint of the movie, there is no clear indication that Gandalf ever found out about Gollum and his relation to the One Ring. In the beginning of The Fellowship of the Ring, Gandalf remarks that the ring has been called "precious" by Gollum before, after Bilbo calls it such. He also indicates to Frodo that he "searched everywhere, but the enemy found [Gollum] first". I ask this question because, in The Desolation of Smaug, Bilbo never explains how he found the ring, much less what it does. Gandalf, of course, is suspicious and (Battle of the Five Armies spoilers)
By the end of the 3rd movie, he indicates that he knows Bilbo has a magic ring, but he does not realize at that moment which ring in particular it is
Frodo knows of Gollum too, but I assume only because he lived with Bilbo and likely heard stories about his adventures. Gandalf hasn't seen Bilbo since the events of The Hobbit (some 60 years I think), so there's no way he would've learned about Gollum from Bilbo in-between The Hobbit and The Lord of the Rings. I assumed, perhaps, that Gandalf somehow learned of Gollum during his research in Minas Terith.
So how and when does Gandalf actually learn about Gollum? And how did Mordor/Sauron learn of Gollum to capture him to find information about the whereabouts of the Ring?