The barrels are mainly used in the quests to be filled up with coal tar making a Barrel of coal-tar or rescue NPCs, as such in the Tourist Trap quest.
If you examine a barrel in front of the Varrock castle, it reads "RuneScape, land of a thousand barrels." This is a reference to countries that have a similar phrase related to them.
If you examine a barrel near the Tea Stall in Varrock that has a green mark on it, it will say "Somewhere there's a very busy cooper.", which is a reference to the Sly Cooper video game series. (A cooper is also someone who makes barrels.)