vomiting ,depending on the age , breed, gender , diet and enviroment ahs different reason . what he puke is gastric acid and since his belly is empty it came out completly foamy. The best option would be to introduce the dog to a vet who do general exam, blood work, fecal exam especially to rule out pancreatitis and other systemic diseases. But till then the best way to reduce the incidences would be :
- small portions but more often ( divide his food to 4 small portion on day)
- completly hypoallergen diet : chicken breast 1 portion and 2 portion cooked rice
- Routinly deworming
wish you luck