Use Plastic Storage Bins to Store Food
Your first line of defense for how to keep ants away from dog food and cat food is to store the food in airtight plastic containers. Avoid keeping your furry friend’s cat food in the bag, as this makes it easier for the ants to invade. 
Keep Your Dog or Cat's Dish Clean at All Times
One of the simplest things you can do to prevent an influx of ants around the food of your dog or cats is to keep their area sparkling clean.
Make sure their bowl is clean and sweep or vacuum the area to prevent any crumbs from attracting the little varmints. Use dish soap and water to clean your pet’s bowls, rinse thoroughly and dry it before filling it with their food and water.
It’s always easier to prevent them from starting in the first place than to have to get rid of them after they succeed in their invasion. 
Make a Moat Around Your Pet’s Food Bowl
Place the bowl of food in a shallow pan of water, like pie tin, cake pan or a food bowl that’s a couple sizes larger than the one you own. When you place the bowl inside the pan of water, there should a ring of water around the food bowl. The water should not be so high that it spills into the pet food. Since ants can’t swim, they’ll drown before they have the chance to get into your pet’s food. 
 Clark, Joan. "How to Keep Ants Out of Cat Food." Tips Bulletin, 09 August 2021, https://www.tipsbulletin.com/how-to-keep-ants-away-from-cat-food/
 Wiggly Wisdom Editorial Staff. "5 Effective Ways to Keep Ants Away From Cat and Dog Food." Wiggly Wisdom, 09 August 2021, https://wigglywisdom.com/how-to-keep-ants-away-from-cat-and-dog-food/
 Western Exterminator Company Editorial Staff. "How To Prevent Your Pets Food From Attracting Ants, 09 August 2021, https://www.westernexterminator.com/ants/how-to-prevent-your-pets-food-from-attracting-ants/