Parasitism by bacteriophages has led to the evolution of a variety of defense mechanisms in their host bacteria. However, it is unclear what factors lead to specific defenses being deployed upon phage infection. To explore this question, we co-evolved the bacterial fish pathogen Flavobacterium columnare and its virulent phage V156 in presence and absence of a eukaryotic host signal (mucin) for sixteen weeks. The presence of mucin leads to a dramatic increase in CRISPR spacer acquisition, especially in low nutrient conditions where over 60% of colonies obtain at least one new spacer. Additionally, we show that the presence of a competitor bacterium further increases CRISPR spacer acquisition in F. columnare. These results suggest that ecological factors are important in determining defense strategies against phages, and that the phage-bacterium interactions on mucosal surfaces may select for the diversification of bacterial immune systems.