V.S.
When we put my son in a bed at 2 years old, he also thought it was great fun to come out every 5 minutes. I didn't want to shut him in his room, so I put a baby gate on his doorway, and the first time he got out of bed he stood at the gate and yelled for us (of course!)--he hated the gate being there. So I told him that if he stayed in his bed, we'd take the gate down. So he climbed back into bed, and watched me set the gate aside. A couple of minutes later, he came out, at which point I walked him back to bed, and put the gate back up, explaining that he had to stay in bed for the gate to be down. Then he yelled from his bed that he was staying in bed (which was pretty amusing), and I said I'd take it down when he fell asleep. Believe it or not, after that it only took a couple more times of putting the gate up for him to "get it" and all I had to do was leave the gate outside his door as a reminder for him to stay in bed. Of course, this only works if your son is not a climber! In that case, he'll just climb over the gate.....