Vaccines activate the immune system to make antibodies to fight against the antigen (i.e., flu virus) that you want protection against.
For example, a typical flu vaccine will have strains of the killed flu virus. Once it is injected into your body, dendritic cells will carry the antigen to activate T cells. Then the T cells will activate all of the other immune cells to fight against that virus.
During this process, memory cells will be made in case the same virus shows up in your body.
Thus, a vaccine prepares you for the actual encounter with the real pathogen.