A community is a cluster of people who work or interact together, usually towards a common goal. Traditionally a neighborhood or town is thought of as a community, but communities form around all kinds of things. For example the cluster of people who commonly ride the same train together to work may bond together as a community.
Online communities form any place where a website helps people reach out to each other. There is an innate human need for human connection, and websites can help fulfill that need. Some websites even make gazillions of dollars offering human connection as a service. And I don't mean prostitution, I mean Facebook and Twitter.