Dobby first appeared in Harry Potter and the Chamber of Secrets, where he was a central character in the story. Dobby served the Malfoy family and its current head Lucius Malfoy. He knew of Malfoy's plans to reopen the Chamber of Secrets using Tom Riddle's (later known as Lord Voldemort) school diary for months before in happened. Dobby snuck out of his home to tell Harry Potter of the danger and attempted to persuade him to remain at home while the horrible things at Hogwarts took place, but without revealing any details of the plot; though he did unintentionally let slip some details, for which he had to punish himself. He attempted to dishearten Harry at first, by intercepting the letters his friends had sent him. When this did not prove enough of a dissuasion, he crashed a cake onto the head of a visitor the Dursleys had to dinner. This would have been succesful, but Ron, Fred and George Weasley rescued Harry in their father's flying car.
Dobby later tried to make Harry remain at home by closing the entrance to Platform 9 and 3/4, but Harry and Ron took the flying car to Hogwarts, which nearly got them expelled. He also enchanted a Bludger to chase only Harry, which managed to knock Harry from his broom with a broken arm. Gilderoy Lockhart attempted to heal Harry's arm, but instead removed the bones from his arm, which left Harry in the hospital wing. While there, Harry saw Colin Creevey brought in, petrified, and was visited again by Dobby.
When Harry discovered who Dobby's master was, Harry tricked Malfoy into setting Dobby free. Dobby was very grateful to Harry Potter, and promised never to try to save his life again.
Dobby wanted to be paid for his service, which meant he had trouble finding work, but he obtained a post at Hogwarts and he is the only elf there who is paid.
Since he began working at Hogwarts, he has, despite his earlier promise, helped Harry several times, though he has been less destructive in these situations. For example, in Harry Potter and the Goblet of Fire, Dobby helped Harry with the Second Task of the Triwizard Tournament and, in Harry Potter and the Order of the Phoenix, showed him the Room of Requirement, which Harry used for his D.A classes.
According to Albus Dumbledore, Dobby's existence under the Malfoys was as miserable as that of Kreacher under Sirius Black.
Dobby was realized as a computer-generated creature voiced by Toby Jones in the film for Harry Potter and the Chamber of Secrets.