The atmosphere in the early times composed of carbon dioxide with very minimal oxygen. These gases came from volcanic eruptions. Some amount of water vapour were also present. As the earth cooled down the vapour condensed and formed water bodies.
Amount of oxygen increased due to photosynthesis which also decreased the carbon dioxide. Some of the carbon dioxide got trapped in rocks fossil fuels and some got dissolved in oceans.