On one hand, social media is a platform that makes it possible to build relationships and connect to people around the world. Social media bounds us together by pre-established interpersonal connections, while each connection has his or her own social network.
It gives us the opportunity to talk to our audiences about ourselves, our products, and our companies. The goal of social media is to increase brand awareness, building customer loyalty, etc. This is a relationship between the owner of the social media and its audiences.
On the other hand, an online community is a place where our users/members can build relationships with each other, further deepening their identity with the community and therefore our brand.
As Etienne Wenger said, communities of practice are groups of people who share a passion for something that they know how to do and who interact regularly to learn how to do it better.
An online community can be formed by people who may not have any interpersonal connections but are bound together by a common interest or topic.
Community members come together, to construct co-created content in a co-created environment to have productive conversations about a topic.
Also, community building can take place on social media, but social media as a whole is not the same as an online community.