Zombies are attracted to bases for a variety of reasons. The most likely explanation is that they are attracted to the noise and activity that goes on at a base.
How to prevent attracting zombies to bases
You can reduce the chance of attracting zombies by keeping doors and windows closed. Curtains, sheets, and metal sheets can be used to block light and prevent zombies from being attracted. Curtains can prevent zombies from seeing the player as they walk past windows. It is also possible to add planks to windows to achieve the same effect.
Does light attract zombies?
PS: This is an issue that has been reported by some players. In a later patch, the noise was removed
It seems that zombies are not attracted to light sources, but they can be attracted to light if it is switched on or off. This is because turning on a light switch makes a noise that can be heard by zombies in a large radius.