When used as an interjection (like yes or no), it basically means "on the contrary". If someone said to you "Der Apfel ist groß" but the apple is actually small, you could say "Doch, der Apfel ist klein!". It's not always positive or negative, it's like a disagreement with what someone has said to you.
Yes, that's one of the many uses of "doch". Here's the best article I've found so far on "doch"; especially note its handy use in arguments between schoolboys https://yourdailygerman.wordpress.com/2012/02/27/meaning-of-doch/
"Doch" is used instead of yes, if somebody asks you a question in a negative form and you want to answer in a positive form... Better give you an example:
"Du hast keine Pinguine, oder?" (You don't have any penguins, right?) ["oder" means 'or' most of the time, but when put at the end of a question, it means something like 'right', 'am I right']
"Doch, ich habe fünf!" (Yes, I have five!)
And if somebody asks you a question in a positive form, you just use "Ja" to say yes.
"Hast du Pinguine?" (Do you have penguins?)
"Ja, ich habe fünf!" (Yes, I have five!)
To native English speakers: "Doch" is kind of like "yuh-huh!" For instance, if you're arguing with someone, it would go "Nein!" "Doch!" "Nein!" "Doch!" So it's yes, but when you're refuting something else.
If someone asked "Willst du nicht Kaffee trinken?" You could respond, "Doch!" meaning, "yes, I do want coffee" but if they asked "Willst du Kaffee trinken?" you would answer with "Ja," since you're not refuting something.
Hope that makes sense. :)