I disagree - at a gym, the experience is completely voluntary and the group is self-selecting. You may be bonding, but with people already like you.
The key with military is being forced to do something you hate alongside complete strangers with little opportunity to socialize outside of the group, under threat of court martial for leaving. And the group of strangers may change at any time. You really have to learn to get along, or work people you don't respect or hate.
Everybody is like you in some way or other but in a BJJ gym, for example, you will be forced to engage with people of different genders, ages, political affiliations, religious beliefs, intensity, IQ, toughness, education. I do not discount the diversity of the military - if service is mandatory - but in civilian life a BJJ gym might be the most practical analogue.
The key with military is being forced to do something you hate alongside complete strangers with little opportunity to socialize outside of the group, under threat of court martial for leaving. And the group of strangers may change at any time. You really have to learn to get along, or work people you don't respect or hate.