Years of practice. Closing the door is a good strategy. I can't do the 'earphones in, work mode on' strategy, music is a distraction - so simply put, years of practice.
I've heard good things about the book Indistractable by Nir Eyal. I'll get around to reading it when I'm not busy / distracted.