The Origins of Cooperative Bacterial Communities