In 1866 Prussia had gone to war with Austria-Hungry as Bismarck hadn’t wanted to tie the new Germany to, what he called, a decaying power
By 1878 German relations with Russia were strained due to Bismarck being the most vocal opposition to Russia’s ambitions in the Balkans during the Congress of Berlin that year
Austria-Hungry was a natural ally as they too were worried about Russian influence in the Balkans