Two quick stories here:
The first is from my own military experience in the 1980s. I attended Army National Guard OCS (Officer Candidate School) where the officers in charge of the candidates stood side-by-side with the base chaplain and basically compelled everyone to attend Sunday services. In formation, we were asked to "raise your hand if you object to attending a non-denominational service" (as if the non-denominational part would make the difference for anyone who objected). About 4 people, myself included, raised hands - which I think we all knew was inviting a sh*tstorm, so it's hard to say how many others might have otherwise objected. The commanding officer and the chaplain shot each other smug glances as the c.o. went to each of us individually and "got in our faces". I was the last one with my hand up - the others had given up and frankly, I was ready to as well. I was pulled aside and sent to the C.O.'s office, where he badgered me some more. He told me that it was all or nothing - that if the whole unit didn't attend services, no one would. I would be personally responsible if I caused those services not to go forward. I was extremely cognizant of the fact that I could easily be kicked out of the program - something I had worked hard for - if I pursued my rights. I told the C.O. that I wasn't religious (I didn't use the "a" word). I think he realized he was on thin ground, so he offered a compromise: attend the service, but you won't be compelled to participate. I weakly agreed (something I have ever since felt sheepish about) and did just that. However, for the next year (the NG's program is a year long), I would get hounded briefly by one or another of the officers for not standing, singing or praying. They'd tap me on the shoulder in chapel and ask why I wasn't participating. I'd have to re-explain each time that I had an agreement with the c.o. and then they'd leave me alone. It was an overt form of harrassment, as it was frequently the same officers each Sunday.
Second story: I was in the military before Desert Storm I, so never saw combat. Therefore in the strictest sense, I cannot claim to be an atheist in a foxhole. However, about 5 years ago I had the misfortune to get caught in a typhoon in Asia in a small sailboat (<30'). Riding out 30-40' waves and 50-60kt winds was, shall we say, a life-changing experience. At one point, after a dismasting, I called the wife on a sat phone to say goodbye - I didn't think we'd make it (one other guy with me). Despite that, I never once thought of praying to god(s). Obviously, we did make it, but it was very much touch and go for a few days.