As soon as you see zerg on 2 base you should be using your sentry energy to send a halucination to see what they're doing. Once you see the infestation pit immediately throw down a robo bay. This is roughly the same time that the swarm hosts begin burrowing outside your base. Throw down about 4-5 cannons at the same time as your robo bay. As soon as you feel you can afford another robo throw it down. You should prioritize more collossi over range at this point. The cannons will stall enough time that you can get 3+ collossi out and then it should be really easy to kill all the swarm host. The locusts WILL kill your buildings(at least some of them). Once they do you should have more room to micro your collossi so leave ur sentries behind your cannons and stutter step the collossi back, you shouldn't take anymore damage once you have 2 or 3. Since you should have range at this point just chip away at the spore crawlers and swarm hosts. You can even ff on top or behind the swarm host so they cant run away.
Once you break the contain the game is basically over as they wont have any econ to do anything else.