Gloucestershire reached 253-6 with four balls to spare after Cockbain shared a stand of 172 with Benny Howell (81).
Lukas Carey was Glamorgan's best bowler with four for 38.
Glamorgan made 252-9 thanks to openers Jacques Rudolph (60) and David Lloyd (49). But Glamorgan lost seamer Ruaidhri Smith to a leg injury suffered while bowling only his second over.
Both teams now play their opening first-class friendlies against student opposition, starting on Tuesday 28 March. Glamorgan host Cardiff MCCU while Gloucestershire face Durham MCCU in Bristol.
Gloucestershire beat Glamorgan by four wickets in their pre-season friendly thanks to Ian Cockbain's 125 not out.