There are many diseases that, if you catch them once, you will never catch again. Measles is a good example, as is chicken pox. What happens with these diseases is that they make it into your body and start reproducing. The immune system gears up to eliminate them. In your body you already have B cells that can recognize the virus and produce antibodies for it. However, there are only a few of these cells for each antibody. Once a particlular disease is recognized by these few specific B cells, the B cells turn into plasma cells, clone themselves and start pumping out antibodies. This process takes time, but the disease runs it course and is eventually eliminated. However, while it is being eliminated, other B cells for the disease clone themselves but do not generate antibodies. This second set of B cells remains in your body for years, so if the disease reappears your body is able to eliminate it immediately before it can do anything to you.
A vaccine is a weakened form of a disease. It is either a killed form of the disease, or it is a similar but less virulent strain. Once inside your body your immune system mounts the same defense, but because the disease is different or weaker you get few or no symptoms of the disease. Now, when the real disease invades your body, your body is able to eliminate it immediately.
Vaccines exist for all sorts of diseases, both viral and bacterial: measles, mumps, whooping cough, tuberculosis, smallpox, polio, typhoid, etc.
Many diseases cannot be cured by vaccines, however. The common cold and Influenza are two good examples. These diseases either mutate so quickly or have so many different strains in the wild that it is impossible to inject all of them into your body. Each time you get the flu, for example, you are getting a different strain of the same disease.