It seems likely that a formal military (like a standing one, the sort we would be familiar with in modern times) would be incompatible with anarchy - if a part of what we are against is class society and/or social stratification, maintaining a specialized warrior class seems pretty unanarchic (as human pointed out in their comment).
That doesn't mean anarchists can't fight or wage war or defend themselves. Some examples include the Makhnovschina in the Ukraine, who waged both offensive and defensive war through the Ukraine during the Russian Revolution (against both the Red and White armies), The anarchist militias of the CNT/FAI during the Spanish Revolution, or arguably, currently in Kurdish resistance to both Turkey and ISIS especially in terms of the YPG & YPJ forces, though there are a lot of folks who question the pedigree of Kurdish anarchism.
I think it is also possible to look to the fighting forces from various indigenous cultures that were not explicitly anarchist but that were non- or less- hierarchical, There are examples of these from almost every continent, if one takes the time to look for them.