Now the Philistines gathered together their armies to battle, and were gathered together at Shochoh, which belongs to Judah, and pitched between Shochoh and Azekah, in Ephesdammim, (1 Samuel 17: 1)
And David rose up early in the morning, and left the sheep with a keeper, and took, and went, as Jesse had commanded him; and he came to the trench, as the host was going forth to the fight, and shouted for the battle. (1 Samuel 17: 20)
What led up to a battle between the Israelites and the Philistines? These two nations had a turbulent history. The following Bible verses cover some of the history prior to David the shepherd going up against Goliath the giant, from Gath.
(1) And the word of Samuel came to all Israel. Now Israel went out against the Philistines to battle, and pitched beside Ebenezer: and the Philistines pitched in Aphek.
(2) And the Philistines put themselves in array against Israel: and when they joined battle, Israel was smitten before the Philistines: and they slew of the army in the field about four thousand men. (1 Samuel 4: 1-2)
The Philistines, at one point, had even taken the ark of the covenant of God.
And she said, The glory is departed from Israel: for the ark of God is taken. (1 Samuel 4: 22)
And the Philistines took the ark of God, and brought it from Ebenezer unto Ashdod. (1 Samuel 5: 1)