My first experiments in fasting were dismal failures in this regard too. I loved fasting a great deal and of course the first time I did it the shock of my senses improving, especially smell and taste, even after only a day or two, made food all that much harder to resist. So I used to fast for two or three days then give in and go get some chips and potato cakes for dinner!
I have had many successes since then but still some ongoing failures, though never quite as bad as those first times. Remembering my failures I have gone into my latest fasts with a different tactic. When I start thinking of food and have urges to eat something bad, I consciously think of fruit instead. I plan how I am going to break my fast before I start it and then start filling in the details when my mind starts trying to offer me junk. I literally imagine eating the fruit of my desire, or even plan in my mind shopping for it etc, relishing it all until the urge diminishes. Let's face it we can't stop thinking about food sometimes but we can, if we try hard enough, change what foods we are thinking about. It's about re-educating your mind to crave better foods. Then having planned how you will break the fast, and imagined it, if you do have to break the fast it is easier to break it on the foods you are imagining. At first I suggest you don't restrict yourself either. Buy plenty of fruit once you've decided to break your fast and eat as much as you like. Your body will stop you from really overdoing it, and even if you overdo it a bit your body will be more forgiving of that than it will of overeating foods that are harder to assimilate.
Another thing that helps is to eat a large fruit salad the night before you start your fast, instead of your usual meal. Make sure you leave at least four hours between the last time you ate and your dinner meal, then have your fruit salad, and eat till you are fully satisfied. If you feel hungry later before bed have another piece of fruit or some fresh juice. Your body will be fully nourished by this meal and will very likely crave little over the next day or two which are usually the worst for cravings. I find it works that way for me. I rarely have any trouble with cravings in the first few days any more.
I hope some of this helps.