Is it possible to defend your house with iron golems?

Solution 1:

If you move into an NPC village, most definitely. My group likes to build our homes inside a village, so we've built iron golems to protect us and the villagers. The wiki seems to indicate that they'll wander off if you try to put them near your home otherwise, though I've no personal experience with that. The wiki also says you can corral them with fences, if they do start wandering off, though of course fencing and adequate lighting prevents your home from being under attack in the first place.

Apparently you can also use vines to corral them, as they see vines as a solid block while you could walk right through. This could create an awesome hidden-grotto effect around your house.

As of recent updates, you can now transform Zombie Villagers back to Villagers, so you could potentially lure said zombies into the area where you want a village and transform them, giving the golem a natural "tether" to the place you want guarded.

Solution 2:

I think the best way is to obtain a lead and attach them to a fence outside your entrance or door.

Solution 3:

Iron golems are 1.4 blocks wide and 2.7 blocks tall, meaning that you can have a wall around your house with gateways 2 blocks off the ground so iron golems can't get out.

Another way is to have walls that have a 1-block gap in between them so you can get through but iron golems can't.

Finally, you can build the iron golem inside your house or if your house is surrounded by a natural barrier like a river, you can build it outside and wall off the rest of the sides.

All these designs are not that great though because skeletons can still shoot iron golems from outside the wall. What you want to do is to have a villager in your house or hidden underground to anchor the iron golem there. Works pretty well but if the iron golem keeps chasing mobs it might eventually get out.

Overall, it would cost less to just build a wall around your house and just leave it like that.