According to my understanding of vaccines, they inject a weakened form of the virus into your body so your immune system can understand the virus and how to kill it. It can remember this information, and when it detects the full form of the virus, it can use the same strategies to kill it as it did with the weakened form.
In short, vaccines train your body to kill the real virus by giving it a "dummy" version.