It's because of gravity !
Just like everything else sticks to earth the thin layer of atmosphere is also kept in place by gravity.
A vacuum is not a force and cannot suck the atmosphere away, but over millions of years earth looses some of it's upper atmosphere...some energized molecules reach escape velocity so that they are leaving the atmosphere into the vacuum of space.
Nothing the worry about, it takes some time to become ''mars'' like in that prospect.
I have the feeling i missed something,.....but never the less