Why do some celestial bodies have atmospheres, and not others? Question is rather self-explanatory. An answer touching upon how/why atmospheres are formed in the first place would be ideal as well. An example of such astral bodies would be The Earth and it's moon. Earth has an atmosphere, while the moon does not. Why is that so?
The amount and kind of gases a body can trap depends on the object's surface temperature, and its density &amp; radius (which refers to it's gravity). 

An object with high gravity and low surface temperature will be able to hold more gases in it's atmosphere. In the case of the Moon, due to its low gravity it could barely trap an atmosphere of Xenon.



You can check this thanks to this amazing plot: http://astro.unl.edu/naap/atmosphere/animations/gasRetentionPlot.html

But this is not all you need to hold an stable atmosphere like the Earth does. The object will also need some protection against the solar wind. In the Earth we have a magnetic field that prevents the solar wind to reach our atmosphere, but in the case of Mars it has a weak and poor magnetic field to defend itself against the solar wind that rips it's atmosphere.