The two primary shopping benefits for military servicemembers are the PX and the Commissary.
The PX is a department store. My understanding is that they are not allowed to price below the local market in the US, but strive to be equal to the lowest price in the area. The PX generates income which is all routed into morale and welfare programs on military installations. No sales tax is charged. They also operate gas stations and convenience stores. Costco usually beats their gas prices by a couple cents.
The Commissary is the grocery store where they are allowed to undercut local stores, and generally do. In the past there was no "store" brand. As a result, local stores would sometimes have their brand of staple products available at lower prices than what was available in the commissary. But in the last few years the policy shifted and there is now a commissary brand, and it is nearly universally cheaper than any grocery stores regular price. The Commissary is subsidized by the DOD, but I don't know by how much. A "surcharge" is added to each item at checkout that is undeclared except for one line at the end of the receipt.
The commissary consistently beats Costco on milk and bananas. Costco wins on rotisserie chicken, dates, mixed nuts, and the quality of various other items. With only two of us in the house, getting bulk perishables like bread, salad and fresh vegetables just didn't work out with Costco. I think Costco is great... I happen to have the commissary option that makes the Costco membership not quite worth it, until I need tires, a new bed, or similar big ticket item.