Our dog is now just over a year old and we went through this.
It’s not easy. We found something that he really liked and he only ever got it when we went out on a walk and he came back to us.
When he came back (no matter how long it took him) he got to play with it for a short while then it was taken away and he was praised.
We then introduced a whistle for meaning to come back so we can recall him if he is out of hearing distance.
Consistency and rarity of playing with the thing he likes the most (for some dogs it’s food) means he now always comes back when the whistle is blown.
We also used a very long lead for a while but it didn’t stop his desire to run after other dogs which is what you want to stop.
It takes time and trying to not get cross. Took him around a week to catch on with no other dogs around and 2 months for it to be very reliable.