Dobby is a house-elf Harry Potter meets the summer before his second year at Hogwarts. When he is first introduced, he serves the Malfoy family (Harry frees him later that same year). He continually makes appearances in the books, helping Harry out because he feels a good deal of affection for him.
 Second book
Dobby makes his first appearance in Harry Potter and the Chamber of Secrets when he tries to warn Harry about the opening of the Chamber of Secrets. He stops Harry's mail, stops him and Ron from getting through the barrier at King's Cross, and sets a rogue bludger on him during a Quidditch match. These are done in an effort to keep Harry safe.
At the end of the book, Harry discovers that his master is Lucius Malfoy, and tricks Lucius into freeing Dobby. This act, above all, makes Dobby incredibly loyal to Harry.
 Fourth book
After being unable to find work for a year, Dobby finds employment at Hogwarts with Winky (another recently freed house elf). Harry, Ron, and Hermione discover Dobby's new situation during their discovery of the kitchens.
 Fifth book
When Harry, Ron and Hermione form Dumbledore's Army, they need to find a place to practice. Dobby informs them of the Room of Requirement, which house elves sometimes refer to as the 'Come and Go Room.' (He later decorates it for Christmas with baubles and a sign saying 'Have a very Harry Christmas'.)
 Sixth book
Harry, convinced that Draco Malfoy is up to something, decides to have Kreacher tail him. When Kreacher arrives wrestling Dobby, Harry is inspired to enlist Dobby to help. This move proves useful, as Kreacher wishes to be loyal to the Malfoys, and most of the information comes from Dobby. With the information, they determine that Malfoy has been using the Room of Requirement, something Dobby knows quite well.
 Final book
Harry has a broken mirror from his godfather, Sirius Black, in which he is convinced he has seen Dumbledore's eye. In desperation, he yells for help while trapped in the basement of Malfoy Manor. Aberforth Dumbledore sends Dobby to help the prisoners, and Harry, Ron, Hermione, Luna Lovegood, Dean Thomas, Mr Ollivander, and Griphook escape to Shell Cottage. As they're escaping, however, Bellatrix throws a silver dagger at Dobby, killing him.
Harry buries him at Shell Cottage, digging the grave without magic and making a headstone saying 'Here lies Dobby, a free elf.'
 Portrayals within films
In the films, Dobby is voiced by Toby Jones.
Dobby has only appeared in two of the Harry Potter films: Harry Potter and the Chamber of Secrets (film) and Harry Potter and the Deathly Hallows Part 1 (film).
 Outward appearance
When he is first introduced in Chamber of Secrets, he is described as having 'large bat-like ears and bulging eyes the size of tennis balls.' He has a high-pitched voice and a long, thin nose and (as a token of his enslavement) wears what looks like a dirty old pillowcase.
Dobby is very quirky, and incredibly unique for a house elf. The other house elves are sometimes ashamed of him. Freedom 'goes to his head,' the other house elves say, because he wants wages. He loves zany socks, and can often be seen wearing an unmatching pair, as well as a stack of Hermione's knitted hats.
 Magical accomplishments and skills
He possesses elf magic, which is very different from wizard magic. For instance, house elves can Apparate within Hogwarts (as well as Malfoy Manor).
Dobby has a collection of colorful, patterned socks.
Ron gives him his maroon Weasley sweater.
In Order of the Phoenix, Hermione knits hats to free house elves, but Dobby takes the all, accruing quite a large collection.