Composite interior and exterior separately
With the help of Cegaton I've found the solution. The main problem was that the window is in the way so it has to be rendered separately. This way there's a hole in the first layer without the background so later on the Alpha Over node can be used.

So, in this case, four render layers are necessary:

Layer 1:

In this layer is the foreground, just the spaceship but without the Window, masking the rest so that there's a transparent hole in the window.



Layer 2:

In this layer it's the Earth without the Atmosphere.



Layer 3:

Just the atmosphere in layer three.



Layer 4:

Here is the Window:





And finally, here's the compositor node setup: